Struct aliri::jwt::JwtRef

source ·
pub struct JwtRef(/* private fields */);
Expand description

A borrowed reference to a JSON Web Token (Jwt)

This type provides custom implementations of Display and Debug to prevent unintentional disclosures of sensitive values. See the documentation on those trait implementations for more information.

Implementations§

source§

impl JwtRef

source

pub fn decompose<H>(&self) -> Result<Decomposed<'_, H>, JwtVerifyError>
where H: for<'de> Deserialize<'de>,

Decomposes the JWT into its parts, preparing it for later processing.

§Errors

Returns an error if the JWT is malformed.

source

pub fn verify<C, H, V>( &self, key: &V, validator: &CoreValidator ) -> Result<Validated<C, H>, JwtVerifyError>
where C: for<'de> Deserialize<'de> + CoreClaims, H: for<'de> Deserialize<'de> + CoreHeaders, V: Verifier<Algorithm = Algorithm>, JwtVerifyError: From<V::Error>,

Verifies a token against a particular JWK and validation plan

If you need to inspect the token first to determine how to verify the token, use decompose() to peek into the JWT.

§Errors

Returns an error if the token is invalid according to the validator.

source

pub fn verify_with_custom<C, H, V, X>( &self, key: &V, validator: &CoreValidator, custom: X ) -> Result<Validated<C, H>, JwtVerifyError>
where C: for<'de> Deserialize<'de> + CoreClaims, H: for<'de> Deserialize<'de> + CoreHeaders, V: Verifier<Algorithm = Algorithm>, JwtVerifyError: From<V::Error>, X: ClaimsValidator<C, H>,

Verifies a token against a particular JWK and validation plan

If you need to inspect the token first to determine how to verify the token, use decompose() to peek into the JWT.

§Errors

Returns an error if the token is invalid according to either the core or custom validators.

source§

impl JwtRef

source

pub const fn from_str(raw: &str) -> &Self

Transparently reinterprets the string slice as a strongly-typed JwtRef

source

pub const fn from_static(raw: &'static str) -> &'static Self

Transparently reinterprets the static string slice as a strongly-typed JwtRef

source

pub fn into_owned(self: Box<JwtRef>) -> Jwt

Converts a Box<JwtRef> into a Jwt without copying or allocating

source

pub const fn as_str(&self) -> &str

Provides access to the underlying value as a string slice.

Trait Implementations§

source§

impl AsRef<JwtRef> for Jwt

source§

fn as_ref(&self) -> &JwtRef

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl AsRef<str> for JwtRef

source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Borrow<JwtRef> for Jwt

source§

fn borrow(&self) -> &JwtRef

Immutably borrows from an owned value. Read more
source§

impl Borrow<str> for JwtRef

source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
source§

impl Debug for JwtRef

By default, this type holds potentially sensitive information. To prevent unintentional disclosure of this value, this type will not print out its contents without explicitly specifying the alternate debug format, i.e. {:#?}. When specified in this form, it will print out the entire header and payload, but will omit the token’s signature. To change the number of characters in the signature that should be printed, specify the amount as a width in the format string, i.e. {:#25?}.

If not specified, a placeholder value will be printed out instead to indicate that it is hiding sensitive information.

If, for any reason, the token does not contain a . character, then the limitations specified above will apply to the token as a whole.

§Example

let token = JwtRef::from_str(concat!(
    "eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5yyY2UjqlUKSSCpFVWzfixfBRTWahiN2PrUuiuxbE"
));

assert_eq!(format!("{:?}", token), "***JWT***");
assert_eq!(format!("{:#?}", token), concat!(
    "\"eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "…\""
));
assert_eq!(format!("{:#5?}", token), concat!(
    "\"eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5y…\""
));
assert_eq!(format!("{:#9999?}", token), concat!(
    "\"eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5yyY2UjqlUKSSCpFVWzfixfBRTWahiN2PrUuiuxbE\""
));
source§

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

Formats the value using the given formatter. Read more
source§

impl<'de: 'a, 'a> Deserialize<'de> for &'a JwtRef

source§

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

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

impl<'de> Deserialize<'de> for Box<JwtRef>

source§

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

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

impl Display for JwtRef

By default, this type holds potentially sensitive information. To prevent unintentional disclosure of this value, this type will not print out its contents without explicitly specifying the alternate format, i.e. {:#}. When specified in this form, it will print out the entire token by default. However, if it is preferable to elide some of the characters in the signature, then that can be modified by specify the quantity as a width in the format string, i.e. {:#10}.

If not specified, a placeholder value will be printed out instead to indicate that it is hiding sensitive information.

If, for any reason, the token does not contain a . character, then the limitations specified above will apply to the token as a whole.

§Example

let token = JwtRef::from_str(concat!(
    "eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5yyY2UjqlUKSSCpFVWzfixfBRTWahiN2PrUuiuxbE"
));

assert_eq!(format!("{}", token), "***JWT***");
assert_eq!(format!("{:#}", token), concat!(
    "eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5yyY2UjqlUKSSCpFVWzfixfBRTWahiN2PrUuiuxbE"
));
assert_eq!(format!("{:#5}", token), concat!(
    "eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5y…"
));
assert_eq!(format!("{:#9999}", token), concat!(
    "eyJhbGciOiJIUzI1NiJ9.",
    "eyJzdWIiOiJBbGlyaSIsImF1ZCI6Im15X2FwaSIsImlzcyI6ImF1dGhvcml0eSJ9.",
    "2N5yyY2UjqlUKSSCpFVWzfixfBRTWahiN2PrUuiuxbE"
));
source§

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

Formats the value using the given formatter. Read more
source§

impl<'a, 'b: 'a> From<&'a Cow<'b, JwtRef>> for &'a JwtRef

source§

fn from(r: &'a Cow<'b, JwtRef>) -> &'a JwtRef

Converts to this type from the input type.
source§

impl From<&JwtRef> for Arc<JwtRef>

source§

fn from(r: &JwtRef) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a JwtRef> for Cow<'a, JwtRef>

source§

fn from(r: &'a JwtRef) -> Self

Converts to this type from the input type.
source§

impl From<&JwtRef> for Jwt

source§

fn from(s: &JwtRef) -> Self

Converts to this type from the input type.
source§

impl From<&JwtRef> for Rc<JwtRef>

source§

fn from(r: &JwtRef) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a str> for &'a JwtRef

source§

fn from(s: &'a str) -> &'a JwtRef

Converts to this type from the input type.
source§

impl From<Jwt> for Box<JwtRef>

source§

fn from(r: Jwt) -> Self

Converts to this type from the input type.
source§

impl Hash for JwtRef

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
source§

impl PartialEq<&JwtRef> for Jwt

source§

fn eq(&self, other: &&JwtRef) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Jwt> for &JwtRef

source§

fn eq(&self, other: &Jwt) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Jwt> for JwtRef

source§

fn eq(&self, other: &Jwt) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<JwtRef> for Jwt

source§

fn eq(&self, other: &JwtRef) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq for JwtRef

source§

fn eq(&self, other: &JwtRef) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for JwtRef

source§

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

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

impl ToOwned for JwtRef

§

type Owned = Jwt

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

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

impl Eq for JwtRef

source§

impl StructuralPartialEq for JwtRef

Auto Trait Implementations§

§

impl Freeze for JwtRef

§

impl RefUnwindSafe for JwtRef

§

impl Send for JwtRef

§

impl !Sized for JwtRef

§

impl Sync for JwtRef

§

impl Unpin for JwtRef

§

impl UnwindSafe for JwtRef

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more