auths_core/crypto/ssh/error.rs
1//! Domain errors for SSH cryptographic operations.
2
3/// Errors from SSH key construction, signing, and encoding operations.
4///
5/// Usage:
6/// ```ignore
7/// match result {
8/// Err(CryptoError::SshKeyConstruction(msg)) => { /* key creation failed */ }
9/// Err(CryptoError::InvalidSeedLength(n)) => { /* wrong seed size */ }
10/// Ok(pem) => { /* success */ }
11/// }
12/// ```
13#[derive(Debug, thiserror::Error)]
14pub enum CryptoError {
15 /// SSH key construction failed.
16 #[error("SSH key construction failed: {0}")]
17 SshKeyConstruction(String),
18
19 /// Signing operation failed.
20 #[error("signing failed: {0}")]
21 SigningFailed(String),
22
23 /// PEM encoding failed.
24 #[error("PEM encoding failed: {0}")]
25 PemEncoding(String),
26
27 /// The seed has an unexpected length.
28 #[error("invalid seed length: expected 32, got {0}")]
29 InvalidSeedLength(usize),
30
31 /// The key format is invalid.
32 #[error("invalid key format: {0}")]
33 InvalidKeyFormat(String),
34}
35
36impl From<auths_crypto::CryptoError> for CryptoError {
37 fn from(e: auths_crypto::CryptoError) -> Self {
38 CryptoError::InvalidKeyFormat(e.to_string())
39 }
40}