pub struct EncryptionService;Expand description
Encryption service for tenant data at rest
Provides AES-256-GCM encryption with tenant-specific keys. Each encryption operation uses a unique randomly-generated nonce.
Implementations§
Source§impl EncryptionService
impl EncryptionService
Sourcepub fn encrypt(
&self,
plaintext: &[u8],
tenant_ctx: &TenantContext,
) -> Result<EncryptedData>
pub fn encrypt( &self, plaintext: &[u8], tenant_ctx: &TenantContext, ) -> Result<EncryptedData>
Encrypt data using the tenant’s encryption key
§Example
use corteq::encryption::EncryptionService;
use corteq::TenantContext;
use uuid::Uuid;
let tenant_ctx = TenantContext::new(
Uuid::new_v4(),
"acme-corp".to_string(),
"encryption-key-32-bytes-long!".to_string(),
);
let service = EncryptionService::new();
let plaintext = b"Sensitive customer data";
let encrypted = service.encrypt(plaintext, &tenant_ctx)
.expect("Encryption failed");Sourcepub fn decrypt(
&self,
encrypted: &EncryptedData,
tenant_ctx: &TenantContext,
) -> Result<Vec<u8>>
pub fn decrypt( &self, encrypted: &EncryptedData, tenant_ctx: &TenantContext, ) -> Result<Vec<u8>>
Decrypt data using the tenant’s encryption key
Returns an error if:
- The data has been tampered with (authentication tag mismatch)
- The wrong encryption key is used
- The nonce is invalid
Trait Implementations§
Source§impl Clone for EncryptionService
impl Clone for EncryptionService
Source§fn clone(&self) -> EncryptionService
fn clone(&self) -> EncryptionService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for EncryptionService
impl Debug for EncryptionService
Auto Trait Implementations§
impl Freeze for EncryptionService
impl RefUnwindSafe for EncryptionService
impl Send for EncryptionService
impl Sync for EncryptionService
impl Unpin for EncryptionService
impl UnwindSafe 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> 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>
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