Skip to main content

KeyRing

Struct KeyRing 

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

A bounded set of token-signing keys with explicit states (issue #137).

A ring is built once — from the environment in a Worker, or programmatically by rotation tooling — and then frozen inside an HmacSigner. It is not ambient request state (ADR 0007): each signer owns its ring, and rotating keys in a running Worker means updating the secrets so the next isolate builds a new ring.

Implementations§

Source§

impl KeyRing

Source

pub const CAPACITY: usize = 4

Maximum number of entries: one signing key plus CAPACITY − 1 verification-only or revoked. A token survives at most CAPACITY − 1 rotations after it was minted; past that, its key is retired and the link is dead by design — the documented cost of being able to revoke a compromised key without a token table (ADR 0014).

Source

pub fn new() -> Self

Source

pub fn len(&self) -> usize

Number of entries, including revoked ones still remembered.

Source

pub fn is_empty(&self) -> bool

Source

pub fn states(&self) -> Vec<(Kid, KeyState)>

Safe view of the ring: each key’s id and state, never its bytes.

Source

pub fn signing_key(&self) -> Option<&RingKey>

The key currently signing new tokens, if any.

Source

pub fn state_of(&self, kid: &Kid) -> Option<KeyState>

Source

pub fn rotate_signing( &mut self, kid: Kid, secret: impl Into<Vec<u8>>, ) -> Result<Option<Kid>, SignerError>

Installs secret as the single signing key, demoting the previous signer to KeyState::VerifyingOnly. If the ring is at capacity, the oldest non-signing entry is retired to make room (its id is kept as a burned tombstone); the retired id is returned.

§Errors

SignerError::SecretTooShort, SignerError::KeyIdTooLong, SignerError::KeyIdTaken, SignerError::KeyRevoked or SignerError::RevokedSecretReuse when the new key is invalid; SignerError::RingFull only in the degenerate ring whose entries are all signing or revoked-with-nothing-to-drop (impossible under Self::CAPACITY ≥ 1 except with hand-built state).

Source

pub fn add_verifying_only( &mut self, kid: Kid, secret: impl Into<Vec<u8>>, ) -> Result<Option<Kid>, SignerError>

Adds a verification-only key — the shape of HARNESS_SECRET_PREVIOUS in the environment wiring. Same capacity and revocation rules as Self::rotate_signing.

§Errors

Identical to Self::rotate_signing: SignerError::SecretTooShort, SignerError::KeyIdTooLong, SignerError::KeyIdTaken, SignerError::KeyRevoked or SignerError::RevokedSecretReuse when the key is invalid, and SignerError::RingFull only in a degenerate ring where nothing can be retired to make room.

Source

pub fn revoke(&mut self, kid: &Kid) -> bool

Marks kid KeyState::Revoked. Its tokens stop verifying immediately, even while its secret stays configured somewhere in the ring — revocation is a state, not a deletion race. Returns whether an entry existed to be revoked; a missing id is still burned as a tombstone, so revoke(prev) survives the moment the operator also drops HARNESS_SECRET_PREVIOUS.

Trait Implementations§

Source§

impl Clone for KeyRing

Source§

fn clone(&self) -> KeyRing

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyRing

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Never prints key material (issue #135).

Source§

impl Default for KeyRing

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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