use std::path::Path; use std::process::Command; pub const KEYCHAIN_NAMESPACE: &str = "geth.keychain.v1@geth.local"; pub const AUTH_OP_NAMESPACE: &str = "geth.auth-op.v1@geth.local"; pub const RESOURCE_GRANT_NAMESPACE: &str = "geth.resource-grant.v1@geth.local"; pub const RESOURCE_SECRET_NAMESPACE: &str = "geth.resource-secret.v1@geth.local"; pub const REVOCATION_NAMESPACE: &str = "geth.revocation.v1@geth.local"; #[derive(Debug, thiserror::Error)] pub enum SshIdentityError { #[error("ssh-keygen failed or is unavailable")] SshKeygenUnavailable, #[error("io error: {0}")] Io(#[from] std::io::Error), } pub fn ensure_ssh_keygen_available() -> Result<(), SshIdentityError> { let status = Command::new("ssh-keygen").arg("-?").status(); match status { Ok(_) => Ok(()), Err(error) if error.kind() == std::io::ErrorKind::NotFound => { Err(SshIdentityError::SshKeygenUnavailable) } Err(error) => Err(SshIdentityError::Io(error)), } } pub fn sign_command(key_path: &Path, namespace: &str, input_path: &Path) -> Command { let mut command = Command::new("ssh-keygen"); command .arg("-Y") .arg("sign") .arg("-f") .arg(key_path) .arg("-n") .arg(namespace) .arg(input_path); command }