1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Error types for the `primitives` module.
/// Errors that can occur in cryptographic primitive operations.
#[non_exhaustive]
#[derive(Debug, thiserror::Error)]
pub enum PrimitivesError {
/// A required feature is not available in this build.
#[error("Feature not available: {0}")]
FeatureNotAvailable(String),
/// The input provided to an operation was invalid.
#[error("Invalid input: {0}")]
InvalidInput(String),
/// Encryption operation failed.
#[error("Encryption failed: {0}")]
EncryptionFailed(String),
/// Decryption operation failed.
#[error("Decryption failed: {0}")]
DecryptionFailed(String),
/// Failed to serialize data.
#[error("Serialization error: {0}")]
SerializationError(String),
/// Failed to deserialize data.
#[error("Deserialization error: {0}")]
DeserializationError(String),
/// Generic error for operations that don't fit other categories.
#[error("{0}")]
Other(String),
/// Error from ML-KEM operations.
#[error("ML-KEM error: {0}")]
MlKem(#[from] crate::primitives::kem::ml_kem::MlKemError),
/// Operation exceeded resource limits.
#[error("Resource limit exceeded: {0}")]
ResourceExceeded(String),
/// Key validation failed during import or use.
#[error("Key validation failed")]
KeyValidationFailed,
/// A cryptographically weak key was detected.
#[error("Weak key detected")]
WeakKey,
/// The key format is invalid or unsupported.
#[error("Invalid key format")]
InvalidKeyFormat,
}
/// Result type alias for [`primitives`](crate::primitives) operations.
pub type Result<T> = std::result::Result<T, PrimitivesError>;