pub struct EncryptionEngine { /* private fields */ }Expand description
Data-at-rest encryption engine.
Wraps AES-256-GCM-SIV with random nonces. Thread-safe (the cipher
is Send + Sync and nonce generation uses OS randomness).
Implementations§
Source§impl EncryptionEngine
impl EncryptionEngine
Sourcepub fn new(key: &[u8; 32]) -> Self
pub fn new(key: &[u8; 32]) -> Self
Create an encryption engine with the given 256-bit key.
The key must be exactly 32 bytes. Typically loaded from
Kubernetes Secrets or the SOCHDB_ENCRYPTION_KEY env var.
Sourcepub fn disabled() -> Self
pub fn disabled() -> Self
Create a disabled (passthrough) encryption engine.
encrypt() and decrypt() are identity operations when disabled.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Whether encryption is active.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, EncryptionError>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<Vec<u8>, EncryptionError>
Encrypt a plaintext block.
Returns [version(1) | nonce(12) | ciphertext+tag(N+16)].
§Performance
~4 GB/s on x86_64 with AES-NI. The overhead is the 13-byte header plus 16-byte auth tag per block.
Sourcepub fn decrypt(&self, encrypted: &[u8]) -> Result<Vec<u8>, EncryptionError>
pub fn decrypt(&self, encrypted: &[u8]) -> Result<Vec<u8>, EncryptionError>
Decrypt an encrypted block produced by encrypt().
Validates the version byte and authentication tag.
Sourcepub fn encrypt_in_place(
&self,
buffer: &mut Vec<u8>,
) -> Result<(), EncryptionError>
pub fn encrypt_in_place( &self, buffer: &mut Vec<u8>, ) -> Result<(), EncryptionError>
Encrypt in-place for zero-copy WAL append.
Prepends the header to the buffer and encrypts the payload region. The buffer is resized to accommodate the header + auth tag.
Auto Trait Implementations§
impl Freeze for EncryptionEngine
impl RefUnwindSafe for EncryptionEngine
impl Send for EncryptionEngine
impl Sync for EncryptionEngine
impl Unpin for EncryptionEngine
impl UnsafeUnpin for EncryptionEngine
impl UnwindSafe for EncryptionEngine
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> 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