pub struct KeyRegistry { /* private fields */ }Expand description
Thread-safe registry of trusted verification keys, keyed by kid.
The registry supports key rotation via Self::rotate: when a new
key is added under the same kid, the old key is preserved for the
grace period so tokens signed by the old key continue to verify
during the cutover.
Bounded by DEFAULT_KEY_KID_CAP distinct kids. When the cap is
reached, Self::add and Self::rotate evict the oldest kid before
inserting a new one. This prevents a misbehaving IdP with thousands of
distinct kids from growing the registry without bound.
Implementations§
Source§impl KeyRegistry
impl KeyRegistry
Sourcepub fn with_cap(cap: usize) -> Self
pub fn with_cap(cap: usize) -> Self
Construct a registry with a custom kid cap (used in tests).
pub fn cap(&self) -> usize
Sourcepub fn add(&self, kid: impl Into<String>, alg: Algorithm, key: KeyMaterial)
pub fn add(&self, kid: impl Into<String>, alg: Algorithm, key: KeyMaterial)
Register a key. Replaces any existing active key with the same
kid and alg (grace-window keys from a rotation are preserved).
If the registry is at its cap, the oldest kid is evicted first.
Sourcepub fn rotate(
&self,
kid: impl Into<String>,
alg: Algorithm,
key: KeyMaterial,
grace: Duration,
)
pub fn rotate( &self, kid: impl Into<String>, alg: Algorithm, key: KeyMaterial, grace: Duration, )
Register a new key under the same kid, marking the previous key as
in grace for the given duration.
Sourcepub fn get(&self, kid: &str, alg: Algorithm) -> Vec<KeyMaterial>
pub fn get(&self, kid: &str, alg: Algorithm) -> Vec<KeyMaterial>
Look up a key by kid and alg. Returns all matching keys that have
not yet exhausted their grace period. Returns an empty Vec if no
matching key is found (caller decides the error mapping).
Trait Implementations§
Source§impl Debug for KeyRegistry
impl Debug for KeyRegistry
Auto Trait Implementations§
impl !Freeze for KeyRegistry
impl !RefUnwindSafe for KeyRegistry
impl Send for KeyRegistry
impl Sync for KeyRegistry
impl Unpin for KeyRegistry
impl UnwindSafe for KeyRegistry
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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