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; 30],
plaintext: &[u8],
) -> Result<Vec<u8>>
pub fn encrypt( &self, lsn: u64, header_bytes: &[u8; 30], plaintext: &[u8], ) -> Result<Vec<u8>>
Encrypt using the current key.
Sourcepub fn decrypt(
&self,
lsn: u64,
header_bytes: &[u8; 30],
ciphertext: &[u8],
) -> Result<Vec<u8>>
pub fn decrypt( &self, lsn: u64, header_bytes: &[u8; 30], ciphertext: &[u8], ) -> Result<Vec<u8>>
Decrypt: try current key first, then previous (if set).
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 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).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for KeyRing
impl RefUnwindSafe for KeyRing
impl Send for KeyRing
impl Sync for KeyRing
impl Unpin for KeyRing
impl UnsafeUnpin for KeyRing
impl UnwindSafe for KeyRing
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