auths_core/crypto/ssh/
error.rs1#[derive(Debug, thiserror::Error)]
14#[non_exhaustive]
15pub enum CryptoError {
16 #[error("SSH key construction failed: {0}")]
18 SshKeyConstruction(String),
19
20 #[error("signing failed: {0}")]
22 SigningFailed(String),
23
24 #[error("PEM encoding failed: {0}")]
26 PemEncoding(String),
27
28 #[error("invalid seed length: expected 32, got {0}")]
30 InvalidSeedLength(usize),
31
32 #[error("invalid key format: {0}")]
34 InvalidKeyFormat(String),
35}
36
37impl auths_crypto::AuthsErrorInfo for CryptoError {
38 fn error_code(&self) -> &'static str {
39 match self {
40 Self::SshKeyConstruction(_) => "AUTHS-E3301",
41 Self::SigningFailed(_) => "AUTHS-E3302",
42 Self::PemEncoding(_) => "AUTHS-E3303",
43 Self::InvalidSeedLength(_) => "AUTHS-E3304",
44 Self::InvalidKeyFormat(_) => "AUTHS-E3305",
45 }
46 }
47
48 fn suggestion(&self) -> Option<&'static str> {
49 match self {
50 Self::InvalidSeedLength(_) => Some("Ensure the seed is exactly 32 bytes"),
51 Self::InvalidKeyFormat(_) => Some("Check that the key file is a valid Ed25519 key"),
52 _ => None,
53 }
54 }
55}
56
57impl From<auths_crypto::CryptoError> for CryptoError {
58 fn from(e: auths_crypto::CryptoError) -> Self {
59 CryptoError::InvalidKeyFormat(e.to_string())
60 }
61}