#[non_exhaustive]pub struct Header<T = Empty> {
pub key_set_url: Option<String>,
pub key_id: Option<String>,
pub certificate_url: Option<String>,
pub certificate_sha1_thumbprint: Option<Thumbprint<20>>,
pub certificate_thumbprint: Option<Thumbprint<32>>,
pub token_type: Option<String>,
pub other_fields: T,
}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 thumbprint: [u8; 32] = Sha256::digest(my_key_cert).into();
let header = Header::empty()
.with_key_id("my-key-id")
.with_certificate_thumbprint(thumbprint);Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
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<Thumbprint<20>>SHA-1 thumbprint of the X.509 certificate for the signing key.
This field is renamed to x5t for serialization.
certificate_thumbprint: Option<Thumbprint<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.
other_fields: TOther fields encoded in the header. These fields may be used by agreement between the producer and consumer of the token to pass additional information. See Sections 4.2 and 4.3 of RFC 7515 for details.
For the token creation and validation to work properly, the fields type must Serialize
to a JSON object.
Note that these fields do not include the signing algorithm (alg) and the token
content type (cty) since both these fields have predefined semantics and are used
internally by the crate logic.
Implementations§
Source§impl<T> Header<T>
impl<T> Header<T>
Sourcepub fn with_key_set_url(self, key_set_url: impl Into<String>) -> Header<T>
pub fn with_key_set_url(self, key_set_url: impl Into<String>) -> Header<T>
Sets the key_set_url field for this header.
Sourcepub fn with_key_id(self, key_id: impl Into<String>) -> Header<T>
pub fn with_key_id(self, key_id: impl Into<String>) -> Header<T>
Sets the key_id field for this header.
Sourcepub fn with_certificate_url(
self,
certificate_url: impl Into<String>,
) -> Header<T>
pub fn with_certificate_url( self, certificate_url: impl Into<String>, ) -> Header<T>
Sets the certificate_url field for this header.
Sourcepub fn with_certificate_sha1_thumbprint(
self,
certificate_thumbprint: impl Into<Thumbprint<20>>,
) -> Header<T>
pub fn with_certificate_sha1_thumbprint( self, certificate_thumbprint: impl Into<Thumbprint<20>>, ) -> Header<T>
Sets the certificate_sha1_thumbprint field for this header.
Sourcepub fn with_certificate_thumbprint(
self,
certificate_thumbprint: impl Into<Thumbprint<32>>,
) -> Header<T>
pub fn with_certificate_thumbprint( self, certificate_thumbprint: impl Into<Thumbprint<32>>, ) -> Header<T>
Sets the certificate_thumbprint field for this header.
Sourcepub fn with_token_type(self, token_type: impl Into<String>) -> Header<T>
pub fn with_token_type(self, token_type: impl Into<String>) -> Header<T>
Sets the token_type field for this header.
Trait Implementations§
Source§impl<T> Decode for Header<T>where
T: Decode,
impl<T> Decode for Header<T>where
T: Decode,
Source§fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Header<T>, Error>where
__CodecInputEdqy: Input,
fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<Header<T>, Error>where
__CodecInputEdqy: Input,
Source§fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
fn decode_into<I>(
input: &mut I,
dst: &mut MaybeUninit<Self>,
) -> Result<DecodeFinished, Error>where
I: Input,
Source§impl<'de, T> Deserialize<'de> for Header<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Header<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Header<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Header<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> Encode for Header<T>where
T: Encode,
impl<T> Encode for Header<T>where
T: Encode,
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
Source§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Source§impl<T> Serialize for Header<T>where
T: Serialize,
impl<T> Serialize for Header<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> EncodeLike for Header<T>where
T: Encode,
impl<T> Eq for Header<T>where
T: Eq,
impl<T> StructuralPartialEq for Header<T>
Auto Trait Implementations§
impl<T> Freeze for Header<T>where
T: Freeze,
impl<T> RefUnwindSafe for Header<T>where
T: RefUnwindSafe,
impl<T> Send for Header<T>where
T: Send,
impl<T> Sync for Header<T>where
T: Sync,
impl<T> Unpin for Header<T>where
T: Unpin,
impl<T> UnwindSafe for Header<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T, Outer> IsWrappedBy<Outer> for T
impl<T, Outer> IsWrappedBy<Outer> for T
Source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
Source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
Source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T. Read moreSource§impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
impl<T, U> TryIntoKey<U> for Twhere
U: TryFromKey<T>,
type Error = <U as TryFromKey<T>>::Error
fn try_into_key(self) -> Result<U, <U as TryFromKey<T>>::Error>
Source§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
Source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from.Source§impl<T, S> UniqueSaturatedInto<T> for S
impl<T, S> UniqueSaturatedInto<T> for S
Source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T.