trelent-hyok 0.1.12

A Rust library implementing Hold Your Own Key (HYOK) encryption patterns with support for multiple cloud providers
Documentation
//! Key generation strategies and implementations.
//!
//! This module provides the core trait and implementations for generating
//! Data Encryption Keys (DEKs). It includes:
//!
//! - Fixed-length random key generation
//! - String-based keys for testing
//! - Custom generation strategies
//! - Common interfaces and traits

pub mod fixed;
pub mod string;
pub mod custom;

use crate::error::generator::GenerateKeyError;

/// A trait for generating Data Encryption Keys (DEK).
///
/// This trait defines the core interface for key generation, allowing
/// different strategies to be implemented while maintaining a consistent
/// interface. Implementations should ensure:
///
/// - Appropriate key lengths
/// - Sufficient entropy
/// - Proper error handling
/// - Thread safety where needed
///
/// # Security
///
/// Implementations should consider:
/// - Using cryptographically secure random number generators
/// - Maintaining key confidentiality
/// - Following cryptographic best practices
/// - Proper handling of sensitive data
///
/// # Example
/// ```no_run
/// use hyokashi::{DEKKeyGenerator, GenerateKeyError};
///
/// struct MyGenerator;
///
/// impl DEKKeyGenerator for MyGenerator {
///     fn generate_key(&self) -> Result<Vec<u8>, GenerateKeyError> {
///         // Implement secure key generation...
///         # Ok(vec![])
///     }
/// }
/// ```
pub trait DEKKeyGenerator {
    /// Generates a new key according to the implementation's strategy.
    ///
    /// # Errors
    ///
    /// Returns a `GenerateKeyError` if key generation fails due to:
    /// - Insufficient entropy
    /// - System errors
    /// - Invalid parameters
    fn generate_key(&self) -> Result<Vec<u8>, GenerateKeyError>;
}