Skip to main content

fraiseql_core/security/kms/
error.rs

1//! KMS-specific error types.
2
3use std::fmt;
4
5/// KMS operation errors.
6#[derive(Debug, Clone)]
7pub enum KmsError {
8    /// Key not found in KMS provider
9    KeyNotFound { key_id: String },
10    /// Encryption operation failed
11    EncryptionFailed { message: String },
12    /// Decryption operation failed
13    DecryptionFailed { message: String },
14    /// Key rotation failed
15    RotationFailed { message: String },
16    /// Connection to KMS provider failed
17    ProviderConnectionError { message: String },
18    /// Invalid configuration
19    InvalidConfiguration { message: String },
20    /// Serialization/deserialization error
21    SerializationError { message: String },
22}
23
24impl fmt::Display for KmsError {
25    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26        match self {
27            Self::KeyNotFound { key_id } => write!(f, "Key not found: {}", key_id),
28            Self::EncryptionFailed { message } => write!(f, "Encryption failed: {}", message),
29            Self::DecryptionFailed { message } => write!(f, "Decryption failed: {}", message),
30            Self::RotationFailed { message } => write!(f, "Key rotation failed: {}", message),
31            Self::ProviderConnectionError { message } => {
32                write!(f, "Provider connection error: {}", message)
33            },
34            Self::InvalidConfiguration { message } => {
35                write!(f, "Invalid configuration: {}", message)
36            },
37            Self::SerializationError { message } => {
38                write!(f, "Serialization error: {}", message)
39            },
40        }
41    }
42}
43
44impl std::error::Error for KmsError {}
45
46pub type KmsResult<T> = Result<T, KmsError>;