Skip to main content

KeyManager

Struct KeyManager 

Source
pub struct KeyManager { /* private fields */ }
Expand description

Manages the rolling window of LogEncryptionKeys used by an crate::encryption::EntryEncryptor.

The “current” key is always used for encryption; on rotation, the old current key is moved into history and a new key takes its place. history is bounded by retention (oldest entries are dropped first once the bound is exceeded). Decryption looks up the right key by the KeyVersion embedded in the payload.

retention of 1 means only the current key is kept; rotating then immediately invalidates the previous key. retention of N means at most N - 1 historical keys plus the current key are retained at any time (so we can decrypt entries from the most recent N versions).

retention is silently clamped to >= 1 at construction time.

Implementations§

Source§

impl KeyManager

Source

pub fn new(initial: LogEncryptionKey, retention: usize) -> Self

Build a new KeyManager with initial as the current key at KeyVersion 1.

retention is clamped to >= 1; that is, at minimum the current key is always kept. retention = 3 means current + 2 historical keys are retained.

Source

pub fn rotate(&mut self, new_key: LogEncryptionKey) -> KeyVersion

Rotate to a new master key, returning the new current version.

The previous current key is moved into history. When the combined size of (current + history) exceeds retention, the oldest historical entry is dropped.

Source

pub fn current(&self) -> (KeyVersion, &LogEncryptionKey)

The current key, paired with its version.

Source

pub fn lookup(&self, version: KeyVersion) -> Option<&LogEncryptionKey>

Look up the key with version, falling back to historical entries.

Returns None if version is older than the retained window (already pruned) or has never existed.

Source

pub fn version_count(&self) -> usize

Number of versions currently retained (current + history).

Always >= 1 because the current key is always present, so KeyManager does not expose an is_empty method.

Source

pub fn retention(&self) -> usize

Configured retention (always >= 1).

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,