trelent-hyok 0.1.12

A Rust library implementing Hold Your Own Key (HYOK) encryption patterns with support for multiple cloud providers
Documentation
//! Encrypted object management and release.
//!
//! This module provides traits and implementations for managing encrypted
//! objects and releasing them in a type-safe manner. It supports:
//!
//! - Type-safe object release
//! - Custom encryption strategies
//! - Error handling
//! - Async operations

use crate::dek::DEK;
use crate::encryption::EncryptionStrategy;
use crate::error::encryption::EncryptionError;
use async_trait::async_trait;

/// A trait for releasing encrypted objects using a specific encryption strategy.
///
/// This trait enables type-safe decryption and conversion of encrypted objects
/// into their original type. Implementations should ensure:
///
/// - Proper decryption
/// - Type safety
/// - Error handling
/// - Resource cleanup
///
/// # Type Parameters
///
/// * `C` - The type of the released (decrypted) object
/// * `S` - The encryption strategy used for decryption
///
/// # Example
/// ```no_run
/// use async_trait::async_trait;
/// use hyokashi::{ReleaseHeldObject, DEK, EncryptionStrategy, EncryptionError};
///
/// struct MyEncryptedObject {
///     data: Vec<u8>
/// }
///
/// #[async_trait]
/// impl<S: EncryptionStrategy + Send> ReleaseHeldObject<String, S> for MyEncryptedObject {
///     async fn release_object(&self, dek: DEK, strategy: &S) -> Result<String, EncryptionError> {
///         // Implement decryption and conversion to String...
///         # Ok(String::new())
///     }
/// }
/// ```
#[async_trait]
pub trait ReleaseHeldObject<C, S: EncryptionStrategy + Send> {
    /// Releases (decrypts) the held object into its original type.
    ///
    /// # Arguments
    ///
    /// * `dek` - Data Encryption Key to use for decryption
    /// * `strategy` - Encryption strategy to use
    ///
    /// # Returns
    ///
    /// The decrypted object of type `C` or an encryption error
    async fn release_object(&self, dek: DEK, strategy: &S) -> Result<C, EncryptionError>;
}