pub trait EncryptionAlgorithm: Sealed {
// Required methods
fn encrypt_data(data: &[u8], key: &[u8; 32]) -> Result<String, CryptoError>;
fn decrypt_data(
encrypted_data: &str,
key: &[u8; 32],
) -> Result<Vec<u8>, CryptoError>;
}Expand description
Core trait for encryption algorithms used in sentinel-crypto. This trait abstracts encryption operations to allow easy switching between different encryption algorithms while maintaining a consistent interface.
Design choice: Trait-based design enables compile-time algorithm selection and allows for future extensions (e.g., ChaCha20-Poly1305, AES-GCM-SIV) without changing the API. The trait is sealed to prevent external implementations that might not meet security requirements.
Required Methods§
Sourcefn encrypt_data(data: &[u8], key: &[u8; 32]) -> Result<String, CryptoError>
fn encrypt_data(data: &[u8], key: &[u8; 32]) -> Result<String, CryptoError>
Sourcefn decrypt_data(
encrypted_data: &str,
key: &[u8; 32],
) -> Result<Vec<u8>, CryptoError>
fn decrypt_data( encrypted_data: &str, key: &[u8; 32], ) -> Result<Vec<u8>, CryptoError>
Decrypts the given encrypted data using the provided key. Expects the input to be a hex-encoded string with nonce + ciphertext.
§Arguments
encrypted_data- The hex-encoded nonce + ciphertextkey- The decryption key
§Returns
The decrypted data
§Errors
Returns CryptoError::Decryption if decryption fails
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.