Skip to main content

trelent_hyok/error/
generator.rs

1//! Error types related to DEK generation and persistence.
2//!
3//! This module provides error types that may occur during Data Encryption Key (DEK)
4//! generation and storage operations. It includes errors for key generation,
5//! persistence operations, and CMK-related issues.
6
7use core::fmt;
8
9use super::cmk::CMKError;
10
11/// Represents an error that can occur during DEK generation.
12///
13/// This error type is used when key generation operations fail, such as:
14/// - Insufficient entropy
15/// - Invalid key parameters
16/// - Algorithm-specific failures
17#[derive(Debug, Eq, PartialEq)]
18pub struct GenerateKeyError(pub String);
19
20impl fmt::Display for GenerateKeyError {
21    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22        write!(f, "Error Generating Key for DEK: {}", self.0)
23    }
24}
25
26/// Describes errors that can occur while persisting DEKs.
27///
28/// This enum represents various failure modes when storing or retrieving DEKs:
29/// - CMK-related errors (token issues, authentication)
30/// - Missing keys
31/// - General storage errors
32#[derive(Debug, Eq, PartialEq)]
33pub enum PersistError {
34    /// Errors related to Customer Managed Key operations
35    CMKError(CMKError),
36    /// Indicates a required key was not found
37    NoKey(String),
38    /// General persistence errors
39    Error(String),
40}
41
42/// Encompasses all possible errors that may be encountered during DEK generation.
43///
44/// This enum combines all error types that can occur during the DEK generation process:
45/// - Persistence errors (storage/retrieval)
46/// - CMK-related errors
47/// - Key generation errors
48#[derive(Debug, Eq, PartialEq)]
49pub enum GeneratorError {
50    /// Errors related to DEK persistence
51    PersistError(PersistError),
52    /// Errors related to Customer Managed Key operations
53    CMKError(CMKError),
54    /// Errors related to key generation
55    GenerateKeyError(GenerateKeyError),
56}