pub struct AsyncEncryptionAdapter<T: EncryptionService + 'static> { /* private fields */ }Expand description
Async adapter for EncryptionService
Wraps a synchronous EncryptionService implementation and provides
async methods that execute the sync operations in a way that doesn’t
block the async runtime.
§Design Rationale
- Domain Purity: Domain traits remain sync and portable
- Infrastructure Flexibility: Async execution is an implementation detail
- Non-Blocking: Uses
spawn_blockingfor CPU-intensive operations - Zero-Cost When Sync: No overhead if used in sync contexts
Implementations§
Source§impl<T: EncryptionService + 'static> AsyncEncryptionAdapter<T>
impl<T: EncryptionService + 'static> AsyncEncryptionAdapter<T>
Sourcepub fn new(service: Arc<T>) -> Self
pub fn new(service: Arc<T>) -> Self
Creates a new async adapter wrapping a sync encryption service
Sourcepub async fn encrypt_chunk_async(
&self,
chunk: FileChunk,
config: &EncryptionConfig,
key_material: &KeyMaterial,
context: &mut ProcessingContext,
) -> Result<FileChunk, PipelineError>
pub async fn encrypt_chunk_async( &self, chunk: FileChunk, config: &EncryptionConfig, key_material: &KeyMaterial, context: &mut ProcessingContext, ) -> Result<FileChunk, PipelineError>
Encrypts a chunk asynchronously
Executes the synchronous encrypt operation in a blocking task pool to avoid blocking the async runtime.
Sourcepub async fn decrypt_chunk_async(
&self,
chunk: FileChunk,
config: &EncryptionConfig,
key_material: &KeyMaterial,
context: &mut ProcessingContext,
) -> Result<FileChunk, PipelineError>
pub async fn decrypt_chunk_async( &self, chunk: FileChunk, config: &EncryptionConfig, key_material: &KeyMaterial, context: &mut ProcessingContext, ) -> Result<FileChunk, PipelineError>
Decrypts a chunk asynchronously
Sourcepub async fn encrypt_chunks_parallel(
&self,
chunks: Vec<FileChunk>,
config: &EncryptionConfig,
key_material: &KeyMaterial,
context: &mut ProcessingContext,
) -> Result<Vec<FileChunk>, PipelineError>
pub async fn encrypt_chunks_parallel( &self, chunks: Vec<FileChunk>, config: &EncryptionConfig, key_material: &KeyMaterial, context: &mut ProcessingContext, ) -> Result<Vec<FileChunk>, PipelineError>
Encrypts multiple chunks in parallel using Rayon (infrastructure concern)
This method demonstrates how parallelization is an infrastructure concern, not a domain concern. The domain just defines encrypt/decrypt.
Uses Rayon’s data parallelism for efficient CPU-bound batch encryption, providing 3-4x speedup on multi-core systems.
Sourcepub async fn decrypt_chunks_parallel(
&self,
chunks: Vec<FileChunk>,
config: &EncryptionConfig,
key_material: &KeyMaterial,
context: &mut ProcessingContext,
) -> Result<Vec<FileChunk>, PipelineError>
pub async fn decrypt_chunks_parallel( &self, chunks: Vec<FileChunk>, config: &EncryptionConfig, key_material: &KeyMaterial, context: &mut ProcessingContext, ) -> Result<Vec<FileChunk>, PipelineError>
Decrypts multiple chunks in parallel using Rayon (infrastructure concern)
Uses Rayon’s data parallelism for efficient CPU-bound batch decryption, providing 3-4x speedup on multi-core systems.
Sourcepub async fn derive_key_material_async(
&self,
password: &str,
config: &EncryptionConfig,
security_context: &SecurityContext,
) -> Result<KeyMaterial, PipelineError>
pub async fn derive_key_material_async( &self, password: &str, config: &EncryptionConfig, security_context: &SecurityContext, ) -> Result<KeyMaterial, PipelineError>
Derives key material from password asynchronously
This is a CPU-intensive operation that benefits from blocking execution.
Sourcepub async fn generate_key_material_async(
&self,
config: &EncryptionConfig,
security_context: &SecurityContext,
) -> Result<KeyMaterial, PipelineError>
pub async fn generate_key_material_async( &self, config: &EncryptionConfig, security_context: &SecurityContext, ) -> Result<KeyMaterial, PipelineError>
Generates random key material asynchronously
Sourcepub fn validate_config(
&self,
config: &EncryptionConfig,
) -> Result<(), PipelineError>
pub fn validate_config( &self, config: &EncryptionConfig, ) -> Result<(), PipelineError>
Validates config (sync operation)
Sourcepub fn supported_algorithms(&self) -> Vec<EncryptionAlgorithm>
pub fn supported_algorithms(&self) -> Vec<EncryptionAlgorithm>
Gets supported algorithms (sync operation)
Sourcepub async fn benchmark_algorithm_async(
&self,
algorithm: &EncryptionAlgorithm,
test_data: &[u8],
) -> Result<EncryptionBenchmark, PipelineError>
pub async fn benchmark_algorithm_async( &self, algorithm: &EncryptionAlgorithm, test_data: &[u8], ) -> Result<EncryptionBenchmark, PipelineError>
Benchmarks algorithm asynchronously
Sourcepub fn wipe_key_material(
&self,
key_material: &mut KeyMaterial,
) -> Result<(), PipelineError>
pub fn wipe_key_material( &self, key_material: &mut KeyMaterial, ) -> Result<(), PipelineError>
Wipes key material (sync operation)
Sourcepub fn store_key_material(
&self,
key_material: &KeyMaterial,
key_id: &str,
security_context: &SecurityContext,
) -> Result<(), PipelineError>
pub fn store_key_material( &self, key_material: &KeyMaterial, key_id: &str, security_context: &SecurityContext, ) -> Result<(), PipelineError>
Stores key material (sync operation - HSM calls might be sync or async depending on implementation)
Sourcepub fn retrieve_key_material(
&self,
key_id: &str,
security_context: &SecurityContext,
) -> Result<KeyMaterial, PipelineError>
pub fn retrieve_key_material( &self, key_id: &str, security_context: &SecurityContext, ) -> Result<KeyMaterial, PipelineError>
Retrieves key material (sync operation)
Sourcepub fn rotate_keys(
&self,
old_key_id: &str,
new_config: &EncryptionConfig,
security_context: &SecurityContext,
) -> Result<String, PipelineError>
pub fn rotate_keys( &self, old_key_id: &str, new_config: &EncryptionConfig, security_context: &SecurityContext, ) -> Result<String, PipelineError>
Rotates keys (sync operation)
Trait Implementations§
Source§impl<T: EncryptionService + 'static> Clone for AsyncEncryptionAdapter<T>
impl<T: EncryptionService + 'static> Clone for AsyncEncryptionAdapter<T>
Auto Trait Implementations§
impl<T> Freeze for AsyncEncryptionAdapter<T>
impl<T> RefUnwindSafe for AsyncEncryptionAdapter<T>where
T: RefUnwindSafe,
impl<T> Send for AsyncEncryptionAdapter<T>
impl<T> Sync for AsyncEncryptionAdapter<T>
impl<T> Unpin for AsyncEncryptionAdapter<T>
impl<T> UnwindSafe for AsyncEncryptionAdapter<T>where
T: RefUnwindSafe,
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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