pub struct EncryptionConfig {
pub algorithm: EncryptionAlgorithm,
pub key_derivation: KeyDerivationFunction,
pub key_size: u32,
pub nonce_size: u32,
pub salt_size: u32,
pub iterations: u32,
pub memory_cost: Option<u32>,
pub parallel_cost: Option<u32>,
pub associated_data: Option<Vec<u8>>,
}Expand description
Encryption configuration that encapsulates all parameters for encryption operations
This configuration struct provides comprehensive control over encryption behavior, including algorithm selection, key derivation parameters, and security settings. The configuration is immutable and thread-safe.
§Configuration Parameters
- Algorithm: The encryption algorithm to use
- Key Derivation: Function for deriving keys from passwords
- Key Size: Size of encryption keys in bytes
- Nonce Size: Size of nonces/initialization vectors in bytes
- Salt Size: Size of salt for key derivation in bytes
- Iterations: Number of iterations for key derivation
- Memory Cost: Memory usage for memory-hard functions (optional)
- Parallel Cost: Parallelism level for key derivation (optional)
- Associated Data: Additional authenticated data (optional)
§Examples
§Security Considerations
- Key Size: Larger keys provide better security but may impact performance
- Iterations: Higher iteration counts increase security but slow key derivation
- Memory Cost: Higher memory usage improves resistance to attacks
- Salt Size: Larger salts prevent rainbow table attacks
- Associated Data: Additional data authenticated but not encrypted
Fields§
§algorithm: EncryptionAlgorithmThe encryption algorithm to use for processing
key_derivation: KeyDerivationFunctionKey derivation function for generating keys from passwords
key_size: u32Size of encryption keys in bytes
nonce_size: u32Size of nonces/initialization vectors in bytes
salt_size: u32Size of salt for key derivation in bytes
iterations: u32Number of iterations for key derivation functions
memory_cost: Option<u32>Memory cost for memory-hard functions (bytes)
parallel_cost: Option<u32>Parallelism level for key derivation functions
associated_data: Option<Vec<u8>>Additional authenticated data (not encrypted)
Implementations§
Source§impl EncryptionConfig
impl EncryptionConfig
Sourcepub fn new(algorithm: EncryptionAlgorithm) -> Self
pub fn new(algorithm: EncryptionAlgorithm) -> Self
Creates a new encryption configuration
Sourcepub fn with_key_derivation(self, kdf: KeyDerivationFunction) -> Self
pub fn with_key_derivation(self, kdf: KeyDerivationFunction) -> Self
Sets key derivation function
Sourcepub fn with_key_size(self, size: u32) -> Self
pub fn with_key_size(self, size: u32) -> Self
Sets key size
Sourcepub fn with_iterations(self, iterations: u32) -> Self
pub fn with_iterations(self, iterations: u32) -> Self
Sets iterations
Sourcepub fn with_memory_cost(self, cost: u32) -> Self
pub fn with_memory_cost(self, cost: u32) -> Self
Sets memory cost (for Argon2)
Sourcepub fn with_parallel_cost(self, cost: u32) -> Self
pub fn with_parallel_cost(self, cost: u32) -> Self
Sets parallel cost (for Argon2)
Sourcepub fn with_associated_data(self, data: Vec<u8>) -> Self
pub fn with_associated_data(self, data: Vec<u8>) -> Self
Sets associated data
Sourcepub fn high_security() -> Self
pub fn high_security() -> Self
Creates a high-security configuration
Sourcepub fn performance_optimized() -> Self
pub fn performance_optimized() -> Self
Creates a performance-optimized configuration
Trait Implementations§
Source§impl Clone for EncryptionConfig
impl Clone for EncryptionConfig
Source§fn clone(&self) -> EncryptionConfig
fn clone(&self) -> EncryptionConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for EncryptionConfig
impl Debug for EncryptionConfig
Source§impl Default for EncryptionConfig
impl Default for EncryptionConfig
Source§impl FromParameters for EncryptionConfig
Implementation of FromParameters for type-safe config extraction.
impl FromParameters for EncryptionConfig
Implementation of FromParameters for type-safe config extraction.
This implementation converts StageConfiguration.parameters HashMap
into a typed EncryptionConfig object.
§Expected Parameters
-
algorithm (required): Encryption algorithm name
- Valid values: “aes256gcm”, “aes128gcm”, “chacha20poly1305”, “xchacha20poly1305”
- Example:
"algorithm" => "aes256gcm"
-
key_size (optional): Key size in bytes
- Default: 32
- Example:
"key_size" => "32"
-
iterations (optional): KDF iterations
- Default: 3
- Example:
"iterations" => "10000"
§Usage Example
use adaptive_pipeline_domain::services::{EncryptionConfig, FromParameters};
use std::collections::HashMap;
let mut params = HashMap::new();
params.insert("algorithm".to_string(), "aes256gcm".to_string());
let config = EncryptionConfig::from_parameters(¶ms).unwrap();Source§fn from_parameters(
params: &HashMap<String, String>,
) -> Result<Self, PipelineError>
fn from_parameters( params: &HashMap<String, String>, ) -> Result<Self, PipelineError>
Auto Trait Implementations§
impl Freeze for EncryptionConfig
impl RefUnwindSafe for EncryptionConfig
impl Send for EncryptionConfig
impl Sync for EncryptionConfig
impl Unpin for EncryptionConfig
impl UnwindSafe for EncryptionConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more