use std::path::Path;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum SshAgentError {
#[error("ssh-add command failed: {0}")]
CommandFailed(String),
#[error("SSH agent not available: {0}")]
NotAvailable(String),
#[error("I/O error: {0}")]
IoError(String),
}
impl auths_crypto::AuthsErrorInfo for SshAgentError {
fn error_code(&self) -> &'static str {
match self {
Self::CommandFailed(_) => "AUTHS-E3901",
Self::NotAvailable(_) => "AUTHS-E3902",
Self::IoError(_) => "AUTHS-E3903",
}
}
fn suggestion(&self) -> Option<&'static str> {
match self {
Self::NotAvailable(_) => Some("Start the SSH agent: eval $(ssh-agent -s)"),
Self::CommandFailed(_) => {
Some("Check that the key file exists and has correct permissions")
}
Self::IoError(_) => Some("Check file permissions"),
}
}
}
pub trait SshAgentPort: Send + Sync {
fn register_key(&self, key_path: &Path) -> Result<(), SshAgentError>;
}