rust_keyvault/
error.rs

1//! Error types for rust-keyvault
2
3use thiserror::Error;
4
5/// Custom `Result` type 
6pub type Result<T> = std::result::Result<T, Error>; 
7
8/// `rust-keyvault` error module
9#[derive(Debug, Error)]
10pub enum Error {
11    /// Key not found in storage
12    #[error("key not found: {0:?}")]
13    KeyNotFound(crate::KeyId),
14
15    /// Key has expired
16    #[error("key has expired")]
17    KeyExpired,
18
19    /// Key is in the wrong state for requested operation
20    #[error("invalid key state: {0}")]
21    InvalidKeyState(String),
22
23    /// Cryptographic operation failed
24    #[error("cryptographic error: {0}")]
25    CryptoError(String),
26
27    /// Storage backend failed
28    #[error("storage error: {0}")]
29    StorageError(String),
30
31    /// Insufficient entropy available
32    #[error("insufficient entropy")]
33    InsufficientEntropy,
34
35    /// Key rotation failed
36    #[error("rotation failed: {0}")]
37    RotationFailed(String),
38
39    /// Serialization/deserilization error
40    #[error("serialisation error: {0}")]
41    SerializationError(String),
42
43    /// Generic I/O error
44    #[error("I/O error: {0}")]
45    IoError(#[from] std::io::Error),
46}
47
48impl Error {
49    /// Create a crypto error with a message
50    pub fn crypto<S: Into<String>>(msg: S) -> Self {
51        Self::CryptoError(msg.into())
52    }
53
54    /// Create a storage error with a message
55    pub fn storage<S: Into<String>>(msg: S) -> Self {
56        Self::StorageError(msg.into())
57    }
58}