Skip to main content

Jwk

Struct Jwk 

Source
#[non_exhaustive]
pub struct Jwk { pub algorithm: Algorithm, pub operations: HashSet<KeyOperation>, pub material: KeyMaterial, pub kid: Option<KeyId>, pub scope: Option<Scope>, }
Expand description

JWK, almost to spec (https://datatracker.ietf.org/doc/html/rfc7517) but not quite the same because it’s annoying to implement.

This is the serialized form of a key, with plain fields you can build and edit. It is not usable on its own: call import to validate it and get a usable Key, and Key::export to go back the other way. What that key may do is whatever key_ops allows, so a verify-only JWK imports fine and simply cannot sign.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§algorithm: Algorithm

The algorithm used by the key.

§operations: HashSet<KeyOperation>

The permitted operations, defaulting to sign and verify when key_ops is absent (optional per RFC 7517 section 4.3).

§material: KeyMaterial

The key material. Defaults to KeyMaterial::OCT when kty is absent.

§kid: Option<KeyId>

The key ID, useful for rotating keys.

§scope: Option<Scope>

Optional authorization limits for tokens signed by this key.

Implementations§

Source§

impl Jwk

Source

pub fn serialize<__S>( __self: &Jwk, __serializer: __S, ) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Source§

impl<'de> Jwk

Source

pub fn deserialize<__D>(__deserializer: __D) -> Result<Jwk, __D::Error>
where __D: Deserializer<'de>,

Source§

impl Jwk

Source

pub fn new(algorithm: Algorithm, material: KeyMaterial) -> Self

A key that can both sign and verify, with no key ID or scope.

Set the remaining fields on the returned value. The struct is #[non_exhaustive], so building it this way keeps working as JWK parameters are added.

Source

pub fn import(self) -> Result<Key>

Validate the parameters and import this as a usable Key.

The inverse of Key::export. Named rather than only a TryFrom impl so the conversion is discoverable from here, and import/export rather than validate because the validate methods elsewhere in this crate check without converting.

Trait Implementations§

Source§

impl Clone for Jwk

Source§

fn clone(&self) -> Jwk

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<'de> Deserialize<'de> for Jwk

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<&Key> for Jwk

Source§

fn from(key: &Key) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Jwk

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<Jwk> for Key

Source§

type Error = Error

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

fn try_from(jwk: Jwk) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

§

impl Freeze for Jwk

§

impl RefUnwindSafe for Jwk

§

impl Send for Jwk

§

impl Sync for Jwk

§

impl Unpin for Jwk

§

impl UnsafeUnpin for Jwk

§

impl UnwindSafe for Jwk

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = 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