Skip to main content

EncryptionConfig

Struct EncryptionConfig 

Source
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

Source

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).

Source

pub fn from_password_with_algorithm( password: &str, algorithm: EncryptionAlgorithm, ) -> Self

Create encryption config from a password with a specific algorithm.

Source

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).

Source

pub fn from_key_with_algorithm( key: [u8; 32], algorithm: EncryptionAlgorithm, ) -> Self

Create encryption config from a raw key with a specific algorithm.

Source

pub fn with_algorithm(self, algorithm: EncryptionAlgorithm) -> Self

Change the algorithm while keeping the same key.

Source

pub fn algorithm(&self) -> EncryptionAlgorithm

Get the configured algorithm.

Source

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.

Source

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
Source

pub fn encrypt_with_aad( &self, plaintext: &[u8], aad: &[u8], ) -> DbxResult<Vec<u8>>

Encrypt data with Associated Data (AAD).

AAD is authenticated but not encrypted — useful for metadata like table names or column IDs that should be verified but remain readable.

Source

pub fn decrypt_with_aad( &self, encrypted: &[u8], aad: &[u8], ) -> DbxResult<Vec<u8>>

Decrypt data with Associated Data (AAD).

The AAD must match exactly what was used during encryption, otherwise authentication will fail.

Trait Implementations§

Source§

impl Clone for EncryptionConfig

Source§

fn clone(&self) -> EncryptionConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EncryptionConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,