pub struct WalEncryptionKey { /* private fields */ }Expand description
AES-256-GCM key with a random per-lifetime epoch for nonce disambiguation.
The epoch is generated randomly at construction time. Each WAL lifetime (process start, snapshot restore, segment creation) gets a fresh epoch, ensuring that nonces are never reused even if LSNs restart from 1.
Implementations§
Source§impl WalEncryptionKey
impl WalEncryptionKey
Sourcepub fn from_bytes(key: &[u8; 32]) -> Self
pub fn from_bytes(key: &[u8; 32]) -> Self
Create from a 32-byte key with a fresh random epoch.
Sourcepub fn from_file(path: &Path) -> Result<Self>
pub fn from_file(path: &Path) -> Result<Self>
Load key from a file (must contain exactly 32 bytes).
Sourcepub fn encrypt(
&self,
lsn: u64,
header_bytes: &[u8; 30],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt( &self, lsn: u64, header_bytes: &[u8; 30], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypt a payload. Returns ciphertext + auth_tag (16 bytes appended).
lsn: used to derive a deterministic nonceheader_bytes: used as AAD (additional authenticated data)plaintext: the payload to encrypt
Sourcepub fn decrypt(
&self,
epoch: &[u8; 4],
lsn: u64,
header_bytes: &[u8; 30],
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt( &self, epoch: &[u8; 4], lsn: u64, header_bytes: &[u8; 30], ciphertext: &[u8], ) -> Result<Vec<u8>>
Decrypt a payload. Input is ciphertext + auth_tag (16 bytes at end).
epoch: the epoch that was used during encryption (from the segment header)lsn: must match the LSN used during encryptionheader_bytes: must match the header used during encryption (AAD)ciphertext: the encrypted payload (includes 16-byte auth tag)
Trait Implementations§
Source§impl Clone for WalEncryptionKey
impl Clone for WalEncryptionKey
Source§fn clone(&self) -> WalEncryptionKey
fn clone(&self) -> WalEncryptionKey
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 moreAuto Trait Implementations§
impl Freeze for WalEncryptionKey
impl RefUnwindSafe for WalEncryptionKey
impl Send for WalEncryptionKey
impl Sync for WalEncryptionKey
impl Unpin for WalEncryptionKey
impl UnsafeUnpin for WalEncryptionKey
impl UnwindSafe for WalEncryptionKey
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