soft_fido2_crypto/
error.rs1#[cfg(not(feature = "std"))]
4use core::fmt;
5
6#[cfg(feature = "std")]
7use thiserror::Error;
8
9#[cfg(feature = "std")]
11#[derive(Debug, Error)]
12#[non_exhaustive]
13pub enum CryptoError {
14 #[error("Invalid public key")]
16 InvalidPublicKey,
17
18 #[error("Invalid private key")]
20 InvalidPrivateKey,
21
22 #[error("Invalid signature")]
24 InvalidSignature,
25
26 #[error("Decryption failed")]
28 DecryptionFailed,
29
30 #[error("Encryption failed")]
32 EncryptionFailed,
33
34 #[error("Invalid key length: expected {expected}, got {actual}")]
36 InvalidKeyLength { expected: usize, actual: usize },
37
38 #[error("ECDH key agreement failed")]
40 KeyAgreementFailed,
41
42 #[error("Invalid COSE key format")]
44 InvalidCoseKey,
45}
46
47#[cfg(not(feature = "std"))]
49#[derive(Debug)]
50#[non_exhaustive]
51pub enum CryptoError {
52 InvalidPublicKey,
54
55 InvalidPrivateKey,
57
58 InvalidSignature,
60
61 DecryptionFailed,
63
64 EncryptionFailed,
66
67 InvalidKeyLength { expected: usize, actual: usize },
69
70 KeyAgreementFailed,
72
73 InvalidCoseKey,
75}
76
77#[cfg(not(feature = "std"))]
79impl fmt::Display for CryptoError {
80 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
81 match self {
82 Self::InvalidPublicKey => write!(f, "Invalid public key"),
83 Self::InvalidPrivateKey => write!(f, "Invalid private key"),
84 Self::InvalidSignature => write!(f, "Invalid signature"),
85 Self::DecryptionFailed => write!(f, "Decryption failed"),
86 Self::EncryptionFailed => write!(f, "Encryption failed"),
87 Self::InvalidKeyLength { expected, actual } => {
88 write!(
89 f,
90 "Invalid key length: expected {}, got {}",
91 expected, actual
92 )
93 }
94 Self::KeyAgreementFailed => write!(f, "ECDH key agreement failed"),
95 Self::InvalidCoseKey => write!(f, "Invalid COSE key format"),
96 }
97 }
98}
99
100pub type Result<T> = core::result::Result<T, CryptoError>;