Skip to main content

KeyRegistry

Struct KeyRegistry 

Source
pub struct KeyRegistry<K: IsKey> { /* private fields */ }
Expand description

A collection of Key or PublicKey objects.

Implementations§

Source§

impl KeyRegistry<PrivateKey>

Source

pub fn private() -> Self

Create a new private key registry.

Source§

impl KeyRegistry<PublicKey>

Source

pub fn public() -> Self

Create a new public key registry.

Source§

impl KeyRegistry<Key>

Source

pub fn new() -> Self

Create a new key registry that may contain both private and public keys.

Source§

impl<K: IsKey> KeyRegistry<K>

Source

pub fn clear(&mut self)

Clear the registry.

Source

pub fn into_keys(self) -> impl Iterator<Item = K>

Source

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

Add a key to the registry. If the key already exists, it will be replaced. If the key specifies the same kid as another key already added, the new key will replace the old one.

Adding a key, even if it already exists, will make it the active key.

Source

pub fn remove_key(&mut self, key: &K)

Remove a key from the registry by its key.

Source

pub fn remove_kid(&mut self, kid: &str) -> bool

Remove a key from the registry by its kid. Note: O(N).

Source

pub fn len(&self) -> usize

Get the number of keys in the registry.

Source

pub fn is_empty(&self) -> bool

Check if the registry is empty.

Source

pub fn add_from_jwkset(&mut self, jwkset: &str) -> Result<usize, KeyError>

Add keys from a JWKSet.

Source

pub fn add_from_pem(&mut self, pem: &str) -> Result<usize, KeyError>

Add keys from a PEM file.

Source

pub fn add_from_any(&mut self, source: &str) -> Result<usize, KeyError>

Add keys from a source string which can be either a JWK set or a PEM file with 1 or more keys.

Source

pub fn to_pem(&self) -> String

Source

pub fn to_json(&self) -> Result<String, KeyError>

Source

pub fn unsafely_decode_without_validation( &self, token: &str, ) -> Result<HashMap<String, Any>, ValidationError>

Decode a token without validating the signature.

Source

pub fn validate( &self, token: &str, ctx: &ValidationContext, ) -> Result<HashMap<String, Any>, ValidationError>

Source

pub fn sign( &self, claims: HashMap<String, Any>, ctx: &SigningContext, ) -> Result<String, SignatureError>

Source§

impl KeyRegistry<PrivateKey>

Source

pub fn can_sign(&self) -> bool

Source

pub fn can_validate(&self) -> bool

Source

pub fn has_private_keys(&self) -> bool

Source

pub fn has_public_keys(&self) -> bool

Source

pub fn has_symmetric_keys(&self) -> bool

Source§

impl KeyRegistry<PublicKey>

Source

pub fn can_sign(&self) -> bool

Source

pub fn can_validate(&self) -> bool

Source

pub fn has_public_keys(&self) -> bool

Source

pub fn has_private_keys(&self) -> bool

Source

pub fn has_symmetric_keys(&self) -> bool

Source§

impl KeyRegistry<Key>

Source

pub fn can_sign(&self) -> bool

Source

pub fn can_validate(&self) -> bool

Source

pub fn has_private_keys(&self) -> bool

Source

pub fn has_public_keys(&self) -> bool

Source

pub fn has_symmetric_keys(&self) -> bool

Source

pub fn to_pem_public(&self) -> Result<String, KeyError>

Export the registry as a PEM file containing only the public keys. This will fail if the registry contains symmetric keys.

Source

pub fn to_json_public(&self) -> Result<String, KeyError>

Export the registry as a JSON object containing only the public keys. This will fail if the registry contains symmetric keys.

Trait Implementations§

Source§

impl<K: IsKey> Default for KeyRegistry<K>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K> Freeze for KeyRegistry<K>

§

impl<K> RefUnwindSafe for KeyRegistry<K>
where <K as IsKey>::Inner: RefUnwindSafe,

§

impl<K> Send for KeyRegistry<K>
where <K as IsKey>::Inner: Send,

§

impl<K> Sync for KeyRegistry<K>
where <K as IsKey>::Inner: Sync,

§

impl<K> Unpin for KeyRegistry<K>
where <K as IsKey>::Inner: Unpin,

§

impl<K> UnsafeUnpin for KeyRegistry<K>

§

impl<K> UnwindSafe for KeyRegistry<K>
where <K as IsKey>::Inner: UnwindSafe,

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, 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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V