pub struct EncryptionService { /* private fields */ }Expand description
AES-256-GCM encryption service for data at rest.
Encrypted format: [12-byte nonce][ciphertext + 16-byte tag]
Tracks invocation count per NIST SP 800-38D recommendation to rotate keys before 2^32 encryptions with random nonces.
Implementations§
Source§impl EncryptionService
impl EncryptionService
Sourcepub fn new(provider: Box<dyn KeyProvider>) -> Self
pub fn new(provider: Box<dyn KeyProvider>) -> Self
Create a new encryption service with the given key provider.
Sourcepub fn invocation_count(&self) -> u64
pub fn invocation_count(&self) -> u64
Returns the number of encrypt() calls since creation.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<(Vec<u8>, String), AuthError>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<(Vec<u8>, String), AuthError>
Encrypt data using the current key.
Returns (ciphertext_with_nonce, key_id).
Format: [12-byte nonce][AES-256-GCM ciphertext + 16-byte auth tag]
Sourcepub fn decrypt(&self, data: &[u8], key_id: &str) -> Result<Vec<u8>, AuthError>
pub fn decrypt(&self, data: &[u8], key_id: &str) -> Result<Vec<u8>, AuthError>
Decrypt data using the specified key.
Input format: [12-byte nonce][AES-256-GCM ciphertext + 16-byte auth tag]
Sourcepub fn hmac(&self, data: &[u8]) -> Result<Vec<u8>, AuthError>
pub fn hmac(&self, data: &[u8]) -> Result<Vec<u8>, AuthError>
Compute HMAC-SHA256 over data for integrity verification.
Sourcepub fn verify_hmac(
&self,
data: &[u8],
expected: &[u8],
key_id: &str,
) -> Result<bool, AuthError>
pub fn verify_hmac( &self, data: &[u8], expected: &[u8], key_id: &str, ) -> Result<bool, AuthError>
Verify HMAC-SHA256 integrity.
Sourcepub fn current_key_id(&self) -> Result<String, AuthError>
pub fn current_key_id(&self) -> Result<String, AuthError>
Get the current key ID.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for EncryptionService
impl !UnwindSafe for EncryptionService
impl Freeze for EncryptionService
impl Send for EncryptionService
impl Sync for EncryptionService
impl Unpin for EncryptionService
impl UnsafeUnpin for EncryptionService
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
Mutably borrows from an owned value. Read more
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> ⓘ
Converts
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> ⓘ
Converts
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