Struct jwt_compact::prelude::Header[][src]

#[non_exhaustive]
pub struct Header { pub key_set_url: Option<String>, pub key_id: Option<String>, pub certificate_url: Option<String>, pub certificate_sha1_thumbprint: Option<[u8; 20]>, pub certificate_thumbprint: Option<[u8; 32]>, pub token_type: Option<String>, }
Expand description

JWT header.

See RFC 7515 for the description of the fields. The purpose of all fields except token_type is to determine the verifying key. Since these values will be provided by the adversary in the case of an attack, they require additional verification (e.g., a provided certificate might be checked against the list of “acceptable” certificate authorities).

A Header can be created using Default implementation, which does not set any fields. For added fluency, you may use with_* methods:

use sha2::{digest::Digest, Sha256};

let my_key_cert = // DER-encoded key certificate
let header = Header::default()
    .with_key_id("my-key-id")
    .with_certificate_thumbprint(Sha256::digest(my_key_cert).into());

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.
key_set_url: Option<String>

URL of the JSON Web Key Set containing the key that has signed the token. This field is renamed to jku for serialization.

key_id: Option<String>

Identifier of the key that has signed the token. This field is renamed to kid for serialization.

certificate_url: Option<String>

URL of the X.509 certificate for the signing key. This field is renamed to x5u for serialization.

certificate_sha1_thumbprint: Option<[u8; 20]>

SHA-1 thumbprint of the X.509 certificate for the signing key. This field is renamed to x5t for serialization.

certificate_thumbprint: Option<[u8; 32]>

SHA-256 thumbprint of the X.509 certificate for the signing key. This field is renamed to x5t#S256 for serialization.

token_type: Option<String>

Application-specific token type. This field is renamed to typ for serialization.

Implementations

impl Header[src]

pub fn with_key_set_url(self, key_set_url: impl Into<String>) -> Self[src]

Sets the key_set_url field for this header.

pub fn with_key_id(self, key_id: impl Into<String>) -> Self[src]

Sets the key_id field for this header.

pub fn with_certificate_url(self, certificate_url: impl Into<String>) -> Self[src]

Sets the certificate_url field for this header.

pub fn with_certificate_sha1_thumbprint(
    self,
    certificate_thumbprint: [u8; 20]
) -> Self
[src]

Sets the certificate_sha1_thumbprint field for this header.

pub fn with_certificate_thumbprint(
    self,
    certificate_thumbprint: [u8; 32]
) -> Self
[src]

Sets the certificate_thumbprint field for this header.

pub fn with_token_type(self, token_type: impl Into<String>) -> Self[src]

Sets the token_type field for this header.

Trait Implementations

impl Clone for Header[src]

fn clone(&self) -> Header[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Header[src]

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

Formats the value using the given formatter. Read more

impl Default for Header[src]

fn default() -> Header[src]

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

impl<'de> Deserialize<'de> for Header[src]

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
    __D: Deserializer<'de>, 
[src]

Deserialize this value from the given Serde deserializer. Read more

impl Serialize for Header[src]

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
    __S: Serializer
[src]

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

impl RefUnwindSafe for Header

impl Send for Header

impl Sync for Header

impl Unpin for Header

impl UnwindSafe for Header

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

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

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]