pub struct RotatingKeyProvider { /* private fields */ }Expand description
A key provider with automatic rotation support.
Generates cryptographically random AES-256 keys and rotates them
based on the configured RotationPolicy. Old keys are retained
(up to retain_old_keys) so historical data can still be decrypted.
Thread-safe: uses RwLock for state and AtomicU64 for the
encryption counter (zero contention on the hot read path).
Implementations§
Source§impl RotatingKeyProvider
impl RotatingKeyProvider
Sourcepub fn new(policy: RotationPolicy) -> Self
pub fn new(policy: RotationPolicy) -> Self
Create a new rotating key provider with the given policy.
An initial random key is generated immediately.
Sourcepub fn with_initial_key(
key_bytes: Vec<u8>,
key_id: &str,
policy: RotationPolicy,
) -> Result<Self, AuthError>
pub fn with_initial_key( key_bytes: Vec<u8>, key_id: &str, policy: RotationPolicy, ) -> Result<Self, AuthError>
Create a rotating provider seeded with an existing key.
Useful for migrating from a static key to rotating keys.
Sourcepub fn rotate_now(&self) -> RotationEvent
pub fn rotate_now(&self) -> RotationEvent
Manually trigger key rotation regardless of policy thresholds.
Returns the rotation event.
Sourcepub fn record_encryption(&self)
pub fn record_encryption(&self)
Record that the current key was used for an encryption operation.
Call this from the EncryptionService after each encrypt() call
so that usage-based rotation can be tracked.
Sourcepub fn current_key_usage(&self) -> u64
pub fn current_key_usage(&self) -> u64
Get the current encryption count for the active key.
Sourcepub fn rotation_history(&self) -> Vec<RotationEvent>
pub fn rotation_history(&self) -> Vec<RotationEvent>
Return all rotation events (most recent last).
Sourcepub fn current_key_age(&self) -> Duration
pub fn current_key_age(&self) -> Duration
Returns the current key’s age (time since creation).
Trait Implementations§
Source§impl Debug for RotatingKeyProvider
impl Debug for RotatingKeyProvider
Auto Trait Implementations§
impl !Freeze for RotatingKeyProvider
impl !RefUnwindSafe for RotatingKeyProvider
impl Send for RotatingKeyProvider
impl Sync for RotatingKeyProvider
impl Unpin for RotatingKeyProvider
impl UnsafeUnpin for RotatingKeyProvider
impl UnwindSafe for RotatingKeyProvider
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more