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)]
7#[non_exhaustive]
8pub enum KmsError {
9    /// Key not found in KMS provider
10    KeyNotFound {
11        /// Identifier of the missing key.
12        key_id: String,
13    },
14    /// Encryption operation failed
15    EncryptionFailed {
16        /// Human-readable description of the failure.
17        message: String,
18    },
19    /// Decryption operation failed
20    DecryptionFailed {
21        /// Human-readable description of the failure.
22        message: String,
23    },
24    /// Key rotation failed
25    RotationFailed {
26        /// Human-readable description of the failure.
27        message: String,
28    },
29    /// Connection to KMS provider failed
30    ProviderConnectionError {
31        /// Human-readable description of the connection error.
32        message: String,
33    },
34    /// Invalid configuration
35    InvalidConfiguration {
36        /// Human-readable description of what is misconfigured.
37        message: String,
38    },
39    /// Serialization/deserialization error
40    SerializationError {
41        /// Human-readable description of the serialization failure.
42        message: String,
43    },
44}
45
46impl fmt::Display for KmsError {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        match self {
49            Self::KeyNotFound { key_id } => write!(f, "Key not found: {}", key_id),
50            Self::EncryptionFailed { message } => write!(f, "Encryption failed: {}", message),
51            Self::DecryptionFailed { message } => write!(f, "Decryption failed: {}", message),
52            Self::RotationFailed { message } => write!(f, "Key rotation failed: {}", message),
53            Self::ProviderConnectionError { message } => {
54                write!(f, "Provider connection error: {}", message)
55            },
56            Self::InvalidConfiguration { message } => {
57                write!(f, "Invalid configuration: {}", message)
58            },
59            Self::SerializationError { message } => {
60                write!(f, "Serialization error: {}", message)
61            },
62        }
63    }
64}
65
66impl std::error::Error for KmsError {}
67
68/// Convenience `Result` alias for KMS operations.
69pub type KmsResult<T> = Result<T, KmsError>;