pub struct KeyRing { /* private fields */ }Expand description
Key ring for rotation-aware cookie signing/verification.
active is used to sign new cookies; previous keys are tried for
verification only, letting old cookies remain valid through a rotation.
Each key carries a string kid so callers can log which key admitted a
given cookie when CookieSigned::get_with_kid is used.
Implementations§
Source§impl KeyRing
impl KeyRing
Sourcepub fn new(active_kid: impl Into<String>, active: Key) -> KeyRing
pub fn new(active_kid: impl Into<String>, active: Key) -> KeyRing
Build a key ring with a single active key.
Sourcepub fn with_previous(self, kid: impl Into<String>, key: Key) -> KeyRing
pub fn with_previous(self, kid: impl Into<String>, key: Key) -> KeyRing
Add a previous key. Verification tries the active key first, then each previous key in insertion order.
Sourcepub fn revoke(&mut self, kid: &str) -> bool
pub fn revoke(&mut self, kid: &str) -> bool
Removes a previous key by kid. Cookies signed with that key will no
longer be accepted — call this when a key has been disclosed or
rotated past its retention window. Returns true if a key was removed.
Sourcepub fn previous_kids(&self) -> impl Iterator<Item = &str>
pub fn previous_kids(&self) -> impl Iterator<Item = &str>
Returns the list of currently-trusted previous key ids in verification order. Use this to confirm a revocation took effect or to plan a key rotation.
Sourcepub fn active_kid(&self) -> &str
pub fn active_kid(&self) -> &str
The active key id.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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