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).
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> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.