pub struct EncryptionConfig { /* private fields */ }Expand description
Encryption configuration for data at rest.
Holds the encryption algorithm and derived key material. Once created, can encrypt/decrypt arbitrary byte slices.
§Security Properties
- Fresh random nonce per encryption (12 bytes, CSPRNG)
- AEAD authentication prevents tampering
- Key derived via HKDF-SHA256 from password or raw key
- Zeroization: key material lives only in this struct
§Examples
use dbx_core::storage::encryption::EncryptionConfig;
// From password (most common)
let config = EncryptionConfig::from_password("my-password");
// From raw 256-bit key
let key = [0x42u8; 32];
let config = EncryptionConfig::from_key(key);
// Encrypt → decrypt round-trip
let data = b"hello, encrypted world!";
let enc = config.encrypt(data).unwrap();
let dec = config.decrypt(&enc).unwrap();
assert_eq!(dec, data);Implementations§
Source§impl EncryptionConfig
impl EncryptionConfig
Sourcepub fn from_password(password: &str) -> Self
pub fn from_password(password: &str) -> Self
Create encryption config from a password string.
The password is stretched to a 256-bit key using HKDF-SHA256. Uses the default algorithm (AES-256-GCM-SIV).
Sourcepub fn from_password_with_algorithm(
password: &str,
algorithm: EncryptionAlgorithm,
) -> Self
pub fn from_password_with_algorithm( password: &str, algorithm: EncryptionAlgorithm, ) -> Self
Create encryption config from a password with a specific algorithm.
Sourcepub fn from_key(key: [u8; 32]) -> Self
pub fn from_key(key: [u8; 32]) -> Self
Create encryption config from a raw 256-bit key.
Uses the default algorithm (AES-256-GCM-SIV).
§Panics
Panics if key is not exactly 32 bytes (this is enforced by the type system).
Sourcepub fn from_key_with_algorithm(
key: [u8; 32],
algorithm: EncryptionAlgorithm,
) -> Self
pub fn from_key_with_algorithm( key: [u8; 32], algorithm: EncryptionAlgorithm, ) -> Self
Create encryption config from a raw key with a specific algorithm.
Sourcepub fn with_algorithm(self, algorithm: EncryptionAlgorithm) -> Self
pub fn with_algorithm(self, algorithm: EncryptionAlgorithm) -> Self
Change the algorithm while keeping the same key.
Sourcepub fn algorithm(&self) -> EncryptionAlgorithm
pub fn algorithm(&self) -> EncryptionAlgorithm
Get the configured algorithm.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> DbxResult<Vec<u8>>
pub fn encrypt(&self, plaintext: &[u8]) -> DbxResult<Vec<u8>>
Encrypt a plaintext byte slice.
Returns [nonce (12 bytes)] || [ciphertext + auth_tag].
A fresh random nonce is generated for each call, making it safe to encrypt the same plaintext multiple times.
Sourcepub fn decrypt(&self, encrypted: &[u8]) -> DbxResult<Vec<u8>>
pub fn decrypt(&self, encrypted: &[u8]) -> DbxResult<Vec<u8>>
Decrypt an encrypted byte slice.
Expects [nonce (12 bytes)] || [ciphertext + auth_tag] format
(as produced by encrypt).
Returns the original plaintext, or an error if:
- Data is too short (less than nonce size)
- Authentication fails (data tampered)
- Wrong key used
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 moreAuto Trait Implementations§
impl Freeze for EncryptionConfig
impl RefUnwindSafe for EncryptionConfig
impl Send for EncryptionConfig
impl Sync for EncryptionConfig
impl Unpin for EncryptionConfig
impl UnsafeUnpin 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> 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