pub struct KeyRing { /* private fields */ }Expand description
Key ring supporting dual-key reads for seamless key rotation.
During rotation: new writes use the current key, reads try current then fall back to previous. Once all old data is re-encrypted, the previous key is removed.
Implementations§
Source§impl KeyRing
impl KeyRing
Sourcepub fn new(current: WalEncryptionKey) -> Self
pub fn new(current: WalEncryptionKey) -> Self
Create a key ring with only the current key.
Sourcepub fn with_previous(
current: WalEncryptionKey,
previous: WalEncryptionKey,
) -> Self
pub fn with_previous( current: WalEncryptionKey, previous: WalEncryptionKey, ) -> Self
Create a key ring with current + previous key (for rotation).
Sourcepub fn encrypt(
&self,
lsn: u64,
header_bytes: &[u8; 54],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt( &self, lsn: u64, header_bytes: &[u8; 54], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypt using the current key.
Sourcepub fn encrypt_aad(
&self,
lsn: u64,
aad: &[u8],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt_aad( &self, lsn: u64, aad: &[u8], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypt with a caller-provided AAD slice.
Sourcepub fn decrypt(
&self,
epoch: &[u8; 4],
lsn: u64,
header_bytes: &[u8; 54],
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt( &self, epoch: &[u8; 4], lsn: u64, header_bytes: &[u8; 54], ciphertext: &[u8], ) -> Result<Vec<u8>>
Decrypt: try current key first, then previous (if set).
epoch is the encryption epoch stored in the WAL segment preamble.
This enables seamless key rotation — old data encrypted with the
previous key can still be read while new data uses the current key.
Sourcepub fn decrypt_aad(
&self,
epoch: &[u8; 4],
lsn: u64,
aad: &[u8],
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt_aad( &self, epoch: &[u8; 4], lsn: u64, aad: &[u8], ciphertext: &[u8], ) -> Result<Vec<u8>>
Decrypt with a caller-provided AAD slice.
Sourcepub fn current(&self) -> &WalEncryptionKey
pub fn current(&self) -> &WalEncryptionKey
Get the current key (for encryption operations).
Sourcepub fn has_previous(&self) -> bool
pub fn has_previous(&self) -> bool
Whether a previous key is present (rotation in progress).
Sourcepub fn clear_previous(&mut self)
pub fn clear_previous(&mut self)
Remove the previous key (rotation complete).