pub struct JwtRef(/* private fields */);
Expand description
Implementations§
source§impl JwtRef
impl JwtRef
sourcepub fn decompose<H>(&self) -> Result<Decomposed<'_, H>, JwtVerifyError>where
H: for<'de> Deserialize<'de>,
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.
sourcepub 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>,
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.
sourcepub 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>,
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
impl JwtRef
sourcepub const fn from_str(raw: &str) -> &Self
pub const fn from_str(raw: &str) -> &Self
Transparently reinterprets the string slice as a strongly-typed JwtRef
sourcepub const fn from_static(raw: &'static str) -> &'static Self
pub const fn from_static(raw: &'static str) -> &'static Self
Transparently reinterprets the static string slice as a strongly-typed JwtRef
sourcepub fn into_owned(self: Box<JwtRef>) -> Jwt
pub fn into_owned(self: Box<JwtRef>) -> Jwt
Converts a Box<JwtRef>
into a Jwt
without copying or allocating
Trait Implementations§
source§impl Debug for JwtRef
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§impl<'de: 'a, 'a> Deserialize<'de> for &'a JwtRef
impl<'de: 'a, 'a> Deserialize<'de> for &'a JwtRef
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl<'de> Deserialize<'de> for Box<JwtRef>
impl<'de> Deserialize<'de> for Box<JwtRef>
source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
source§impl Display for JwtRef
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"
));