trelent-hyok 0.1.12

A Rust library implementing Hold Your Own Key (HYOK) encryption patterns with support for multiple cloud providers
Documentation
//! Error types related to DEK generation and persistence.
//!
//! This module provides error types that may occur during Data Encryption Key (DEK)
//! generation and storage operations. It includes errors for key generation,
//! persistence operations, and CMK-related issues.

use core::fmt;

use super::cmk::CMKError;

/// Represents an error that can occur during DEK generation.
///
/// This error type is used when key generation operations fail, such as:
/// - Insufficient entropy
/// - Invalid key parameters
/// - Algorithm-specific failures
#[derive(Debug, Eq, PartialEq)]
pub struct GenerateKeyError(pub String);

impl fmt::Display for GenerateKeyError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "Error Generating Key for DEK: {}", self.0)
    }
}

/// Describes errors that can occur while persisting DEKs.
///
/// This enum represents various failure modes when storing or retrieving DEKs:
/// - CMK-related errors (token issues, authentication)
/// - Missing keys
/// - General storage errors
#[derive(Debug, Eq, PartialEq)]
pub enum PersistError {
    /// Errors related to Customer Managed Key operations
    CMKError(CMKError),
    /// Indicates a required key was not found
    NoKey(String),
    /// General persistence errors
    Error(String),
}

/// Encompasses all possible errors that may be encountered during DEK generation.
///
/// This enum combines all error types that can occur during the DEK generation process:
/// - Persistence errors (storage/retrieval)
/// - CMK-related errors
/// - Key generation errors
#[derive(Debug, Eq, PartialEq)]
pub enum GeneratorError {
    /// Errors related to DEK persistence
    PersistError(PersistError),
    /// Errors related to Customer Managed Key operations
    CMKError(CMKError),
    /// Errors related to key generation
    GenerateKeyError(GenerateKeyError),
}