Skip to main content

qux_pqc/
error.rs

1//! Error types for qux-pqc library
2
3use thiserror::Error;
4
5/// Result type alias for qux-pqc operations
6pub type Result<T> = std::result::Result<T, Error>;
7
8/// Errors that can occur in qux-pqc operations
9#[derive(Error, Debug)]
10pub enum Error {
11    /// Key generation failed
12    #[error("Key generation failed: {0}")]
13    KeyGeneration(String),
14
15    /// Encapsulation failed
16    #[error("Encapsulation failed: {0}")]
17    Encapsulation(String),
18
19    /// Decapsulation failed
20    #[error("Decapsulation failed: {0}")]
21    Decapsulation(String),
22
23    /// Signing failed
24    #[error("Signing failed: {0}")]
25    Signing(String),
26
27    /// Signature verification failed
28    #[error("Signature verification failed")]
29    SignatureVerificationFailed,
30
31    /// Encryption failed
32    #[error("Encryption failed: {0}")]
33    Encryption(String),
34
35    /// Decryption failed
36    #[error("Decryption failed: {0}")]
37    Decryption(String),
38
39    /// Invalid key size
40    #[error("Invalid key size: expected {expected}, got {actual}")]
41    InvalidKeySize {
42        /// Expected key size in bytes
43        expected: usize,
44        /// Actual key size received
45        actual: usize,
46    },
47
48    /// Invalid ciphertext
49    #[error("Invalid ciphertext: {0}")]
50    InvalidCiphertext(String),
51
52    /// Invalid signature
53    #[error("Invalid signature: {0}")]
54    InvalidSignature(String),
55
56    /// Invalid nonce
57    #[error("Invalid nonce: expected {expected} bytes, got {actual}")]
58    InvalidNonce {
59        /// Expected nonce size in bytes
60        expected: usize,
61        /// Actual nonce size received
62        actual: usize,
63    },
64
65    /// Hex decoding error
66    #[error("Hex decoding error: {0}")]
67    HexDecode(#[from] hex::FromHexError),
68
69    /// Base64 decoding error
70    #[error("Base64 decoding error: {0}")]
71    Base64Decode(#[from] base64::DecodeError),
72
73    /// JSON serialization/deserialization error
74    #[error("JSON error: {0}")]
75    Json(#[from] serde_json::Error),
76
77    /// Key storage error
78    #[error("Key storage error: {0}")]
79    KeyStorage(String),
80
81    /// Key not found
82    #[error("Key not found: {0}")]
83    KeyNotFound(String),
84
85    /// Timestamp expired
86    #[error("Signature timestamp expired")]
87    TimestampExpired,
88
89    /// Invalid security level
90    #[error("Invalid security level: {0}")]
91    InvalidSecurityLevel(String),
92}