pub struct UntrustedToken<H = Empty> { /* private fields */ }Expand description
Parsed, but unvalidated token.
The type param (Empty by default) corresponds to the additional information enclosed
in the token Header.
An UntrustedToken can be parsed from a string using the TryFrom implementation.
This checks that a token is well-formed (has a header, claims and a signature),
but does not validate the signature.
As a shortcut, a token without additional header info can be created using Self::new().
§Examples
let token_str = "eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJp\
c3MiOiJqb2UiLA0KICJleHAiOjEzMDA4MTkzODAsDQogImh0dHA6Ly9leG\
FtcGxlLmNvbS9pc19yb290Ijp0cnVlfQ.dBjftJeZ4CVP-mB92K27uhbUJ\
U1p1r_wW1gFWFOEjXk";
let token: UntrustedToken = token_str.try_into()?;
// The same operation using a shortcut:
let same_token = UntrustedToken::new(token_str)?;
// Token header can be accessed to select the verifying key etc.
let key_id: Option<&str> = token.header().key_id.as_deref();§Handling tokens with custom header fields
#[derive(Debug, Clone, Deserialize)]
struct HeaderExtensions {
custom: String,
}
let token_str = "eyJhbGciOiJIUzI1NiIsImtpZCI6InRlc3Rfa2V5Iiwid\
HlwIjoiSldUIiwiY3VzdG9tIjoiY3VzdG9tIn0.eyJzdWIiOiIxMjM0NTY\
3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9._27Fb6nF\
Tg-HSt3vO4ylaLGcU_ZV2VhMJR4HL7KaQik";
let token: UntrustedToken<HeaderExtensions> = token_str.try_into()?;
let extensions = &token.header().other_fields;
println!("{}", extensions.custom);Implementations§
Source§impl<'a> UntrustedToken
impl<'a> UntrustedToken
Sourcepub fn new<S>(s: &'a S) -> Result<UntrustedToken, ParseError>
pub fn new<S>(s: &'a S) -> Result<UntrustedToken, ParseError>
Creates an untrusted token from a string. This is a shortcut for calling the TryFrom
conversion.
Source§impl<H> UntrustedToken<H>
impl<H> UntrustedToken<H>
Sourcepub fn into_owned(self) -> UntrustedToken<H>
pub fn into_owned(self) -> UntrustedToken<H>
Converts this token to an owned form.
Sourcepub fn signature_bytes(&self) -> &[u8] ⓘ
pub fn signature_bytes(&self) -> &[u8] ⓘ
Returns signature bytes from the token. These bytes are not guaranteed to form a valid signature.
Sourcepub fn deserialize_claims_unchecked<T>(
&self,
) -> Result<Claims<T>, ValidationError>where
T: DeserializeOwned,
pub fn deserialize_claims_unchecked<T>(
&self,
) -> Result<Claims<T>, ValidationError>where
T: DeserializeOwned,
Deserializes claims from this token without checking token integrity. The resulting claims are thus not guaranteed to be valid.
Trait Implementations§
Source§impl<H> Clone for UntrustedToken<H>where
H: Clone,
impl<H> Clone for UntrustedToken<H>where
H: Clone,
Source§fn clone(&self) -> UntrustedToken<H>
fn clone(&self) -> UntrustedToken<H>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<H> Debug for UntrustedToken<H>where
H: Debug,
impl<H> Debug for UntrustedToken<H>where
H: Debug,
Source§impl<H> Decode for UntrustedToken<H>
impl<H> Decode for UntrustedToken<H>
Source§fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<UntrustedToken<H>, Error>where
__CodecInputEdqy: Input,
fn decode<__CodecInputEdqy>(
__codec_input_edqy: &mut __CodecInputEdqy,
) -> Result<UntrustedToken<H>, 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, H> Deserialize<'de> for UntrustedToken<H>where
H: Deserialize<'de>,
impl<'de, H> Deserialize<'de> for UntrustedToken<H>where
H: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<UntrustedToken<H>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<UntrustedToken<H>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<H> Encode for UntrustedToken<H>
impl<H> Encode for UntrustedToken<H>
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<H> MaxEncodedLen for UntrustedToken<H>where
Header<H>: MaxEncodedLen,
impl<H> MaxEncodedLen for UntrustedToken<H>where
Header<H>: MaxEncodedLen,
Source§fn max_encoded_len() -> usize
fn max_encoded_len() -> usize
Source§impl<H> PartialEq for UntrustedToken<H>where
H: PartialEq,
impl<H> PartialEq for UntrustedToken<H>where
H: PartialEq,
Source§impl<H> Serialize for UntrustedToken<H>where
H: Serialize,
impl<H> Serialize for UntrustedToken<H>where
H: 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,
Source§impl<'a, H> TryFrom<&'a str> for UntrustedToken<H>where
H: DeserializeOwned,
impl<'a, H> TryFrom<&'a str> for UntrustedToken<H>where
H: DeserializeOwned,
Source§type Error = ParseError
type Error = ParseError
Source§fn try_from(
s: &'a str,
) -> Result<UntrustedToken<H>, <UntrustedToken<H> as TryFrom<&'a str>>::Error>
fn try_from( s: &'a str, ) -> Result<UntrustedToken<H>, <UntrustedToken<H> as TryFrom<&'a str>>::Error>
Source§impl<H> TypeInfo for UntrustedToken<H>
impl<H> TypeInfo for UntrustedToken<H>
impl<H> EncodeLike for UntrustedToken<H>
impl<H> Eq for UntrustedToken<H>where
H: Eq,
impl<H> StructuralPartialEq for UntrustedToken<H>
Auto Trait Implementations§
impl<H> Freeze for UntrustedToken<H>where
H: Freeze,
impl<H> RefUnwindSafe for UntrustedToken<H>where
H: RefUnwindSafe,
impl<H> Send for UntrustedToken<H>where
H: Send,
impl<H> Sync for UntrustedToken<H>where
H: Sync,
impl<H> Unpin for UntrustedToken<H>where
H: Unpin,
impl<H> UnwindSafe for UntrustedToken<H>where
H: 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.