Struct KeyStore

Source
pub struct KeyStore { /* private fields */ }

Implementations§

Source§

impl KeyStore

Source

pub fn new() -> KeyStore

Source

pub async fn new_from(jkws_url: &str) -> Result<KeyStore, Error>

Source

pub fn clear_keys(&mut self)

Source

pub fn key_set_url(&self) -> &str

Source

pub async fn load_keys_from(&mut self, url: &str) -> Result<(), Error>

Source

pub async fn load_keys(&mut self) -> Result<(), Error>

Source

pub fn key_by_id(&self, kid: &str) -> Option<&JwtKey>

Fetch a key by key id (KID)

Source

pub fn keys_len(&self) -> usize

Number of keys in keystore

Source

pub fn add_key(&mut self, key: &JwtKey)

Manually add a key to the keystore

Source

pub fn decode(&self, token: &str) -> Result<Jwt, Error>

Source

pub fn verify_time(&self, token: &str, time: SystemTime) -> Result<Jwt, Error>

Source

pub fn verify(&self, token: &str) -> Result<Jwt, Error>

Verify a JWT token. If the token is valid, it is returned.

A token is considered valid if:

  • Is well formed
  • Has a kid field that matches a public signature `kid
  • Signature matches public key
  • It is not expired
  • The nbf is not set to before now
Source

pub fn last_load_time(&self) -> Option<SystemTime>

Time at which the keys were last refreshed

Source

pub fn keys_expired(&self) -> Option<bool>

True if the keys are expired and should be refreshed

None if keys do not have an expiration time

Source

pub fn set_refresh_interval(&mut self, interval: f64)

Specifies the interval (as a fraction) when the key store should refresh it’s key.

The default is 0.5, meaning that keys should be refreshed when we are halfway through the expiration time (similar to DHCP).

This method does not update the refresh time. Call load_keys to force an update on the refresh time property.

Source

pub fn refresh_interval(&self) -> f64

Get the current fraction time to check for token refresh time.

Source

pub fn load_time(&self) -> Option<SystemTime>

The time at which the keys were loaded None if the keys were never loaded via load_keys or load_keys_from.

Source

pub fn expire_time(&self) -> Option<SystemTime>

Get the time at which the keys are considered expired

Source

pub fn refresh_time(&self) -> Option<SystemTime>

time at which keys should be refreshed.

Source

pub fn should_refresh_time(&self, current_time: SystemTime) -> Option<bool>

Returns Option<true> if keys should be refreshed based on the given current_time.

None is returned if the key store does not have a refresh time available. For example, the load_keys function was not called or the HTTP server did not provide a

Source

pub fn should_refresh(&self) -> Option<bool>

Returns Option<true> if keys should be refreshed based on the system time.

None is returned if the key store does not have a refresh time available. For example, the load_keys function was not called or the HTTP server did not provide a

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,