Skip to main content

JwtKeys

Struct JwtKeys 

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

The verification keys a server holds, shared and replaceable.

Cloning shares the set. JwtKeys::replace swaps the whole set at once for every holder, which is what a JWKS refresher needs: a request takes JwtKeys::current once and verifies against that snapshot, so a swap mid-request changes nothing about the request already running.

A plain RwLock around an Arc: the lock is held only to clone the Arc out, never across a verification, so readers do not wait on each other in any way that matters and a writer waits for nothing but those clones.

Each set, the first and every replacement, also gets a generation, under the same lock as the set itself so the two can never disagree. A crate::JwtCache remembers the generation its entries were verified under and forgets them all when a later one appears; see JwtKeys::generation.

Implementations§

Source§

impl JwtKeys

Source

pub fn new(set: KeySet) -> Self

Hold set.

Source

pub fn from_config( secret: Option<&str>, secret_is_base64: bool, ) -> Result<Option<Self>, JwtKeyError>

The keys for PGRST_JWT_SECRET, or None when no secret is set.

Call it where the configuration is read, and treat an error as a reason not to start.

Source

pub fn current(&self) -> Arc<KeySet> ⓘ

The set as it is now.

Source

pub fn generation(&self) -> u64

Which set this is: a number no earlier set, of this handle or any other in the process, was given, and greater than all of theirs.

Read before a token is verified and compared after, it says whether the set the token was verified against is still the one in force. Increasing rather than merely different, so that a request which read it before a replacement is recognisably behind one that read it after, and cannot put a cache back on the old set. Process-wide rather than per handle, so that a cache that outlives one JwtKeys – a Worker isolate’s, when its configuration changes – sees the next one’s sets as later too.

Source

pub fn replace(&self, set: KeySet)

Replace the set, for every holder of this handle.

A crate::JwtCache that sees the change forgets every token it holds, so a token verified by a key that has since been withdrawn is refused from the next request on – not answered from the cache until its entry expires. Replacing a set with an identical one forgets them too, which costs one verification per token; a JWKS refresher that fetched the same set again does not call this.

Trait Implementations§

Source§

impl Clone for JwtKeys

Source§

fn clone(&self) -> Self

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 JwtKeys

Source§

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

Formats the value using the given formatter. 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> 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> MaybeSendSync for T
where T: Send + Sync + ?Sized,

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