pub struct EncryptedWal { /* private fields */ }Expand description
Encrypted Write-Ahead Log.
Encrypts each WAL record before writing it to disk. During replay, records are decrypted and deserialized.
§Security Properties
- Each record is independently encrypted with a fresh nonce
- AAD prevents record type confusion
- Records cannot be read without the encryption key
§Examples
use dbx_core::wal::encrypted_wal::EncryptedWal;
use dbx_core::wal::WalRecord;
use dbx_core::storage::encryption::EncryptionConfig;
use std::path::Path;
let enc = EncryptionConfig::from_password("secret");
let wal = EncryptedWal::open(Path::new("./wal.log"), enc).unwrap();
let record = WalRecord::Insert {
table: "users".to_string(),
key: b"user:1".to_vec(),
value: b"Alice".to_vec(),
ts: 0,
};
wal.append(&record).unwrap();
wal.sync().unwrap();Implementations§
Source§impl EncryptedWal
impl EncryptedWal
Sourcepub fn open(path: &Path, encryption: EncryptionConfig) -> DbxResult<Self>
pub fn open(path: &Path, encryption: EncryptionConfig) -> DbxResult<Self>
Open or create an encrypted WAL file.
Sourcepub fn append(&self, record: &WalRecord) -> DbxResult<u64>
pub fn append(&self, record: &WalRecord) -> DbxResult<u64>
Append an encrypted record to the WAL.
The record is serialized to JSON, encrypted, base64-encoded, and written as a single line.
Sourcepub fn current_sequence(&self) -> u64
pub fn current_sequence(&self) -> u64
Returns the current sequence number.
Sourcepub fn encryption_config(&self) -> &EncryptionConfig
pub fn encryption_config(&self) -> &EncryptionConfig
Get a reference to the encryption config.
Sourcepub fn rekey(&mut self, new_encryption: EncryptionConfig) -> DbxResult<usize>
pub fn rekey(&mut self, new_encryption: EncryptionConfig) -> DbxResult<usize>
Re-key the WAL with a new encryption configuration.
Reads all existing records, decrypts with the current key, then re-writes them encrypted with the new key. The old WAL file is atomically replaced.
§Warning
Callers should ensure no concurrent writes during rekey.
Auto Trait Implementations§
impl !Freeze for EncryptedWal
impl RefUnwindSafe for EncryptedWal
impl Send for EncryptedWal
impl Sync for EncryptedWal
impl Unpin for EncryptedWal
impl UnsafeUnpin for EncryptedWal
impl UnwindSafe for EncryptedWal
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