pub struct Renamed<A> { /* private fields */ }Expand description
Algorithm that uses a custom name when creating and validating tokens.
§Examples
use jwt_compact_frame::{alg::{Hs256, Hs256Key}, prelude::*, Empty, Renamed};
let alg = Renamed::new(Hs256, "HS2");
let key = Hs256Key::new(b"super_secret_key_donut_steel");
let token_string = alg.token(&Header::empty(), &Claims::empty(), &key)?;
let token = UntrustedToken::new(&token_string)?;
assert_eq!(token.algorithm(), "HS2");
// Note that the created token cannot be verified against the original algorithm
// since the algorithm name recorded in the token header doesn't match.
assert!(Hs256.validator::<Empty>(&key).validate(&token).is_err());
// ...but the modified alg is working as expected.
assert!(alg.validator::<Empty>(&key).validate(&token).is_ok());Implementations§
Trait Implementations§
Source§impl<A> Algorithm for Renamed<A>where
A: Algorithm,
impl<A> Algorithm for Renamed<A>where
A: Algorithm,
Source§type SigningKey = <A as Algorithm>::SigningKey
type SigningKey = <A as Algorithm>::SigningKey
Key used when issuing new tokens.
Source§type VerifyingKey = <A as Algorithm>::VerifyingKey
type VerifyingKey = <A as Algorithm>::VerifyingKey
Key used when verifying tokens. May coincide with
Self::SigningKey for symmetric
algorithms (e.g., HS*).Source§fn name(&self) -> Cow<'static, str>
fn name(&self) -> Cow<'static, str>
Returns the name of this algorithm, as mentioned in the
alg field of the JWT header.Source§impl<A> Encode for Renamed<A>where
A: Encode,
impl<A> Encode for Renamed<A>where
A: Encode,
Source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
If possible give a hint of expected size of the encoding. Read more
Source§fn encode_to<__CodecOutputEdqy>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )
Convert self to a slice and append it to the destination.
Source§fn using_encoded<R, F>(&self, f: F) -> R
fn using_encoded<R, F>(&self, f: F) -> R
Convert self to a slice and then invoke the given closure with it.
Source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
Calculates the encoded size. Read more
impl<A> Copy for Renamed<A>where
A: Copy,
impl<A> EncodeLike for Renamed<A>where
A: Encode,
Auto Trait Implementations§
impl<A> Freeze for Renamed<A>where
A: Freeze,
impl<A> RefUnwindSafe for Renamed<A>where
A: RefUnwindSafe,
impl<A> Send for Renamed<A>where
A: Send,
impl<A> Sync for Renamed<A>where
A: Sync,
impl<A> Unpin for Renamed<A>where
A: Unpin,
impl<A> UnwindSafe for Renamed<A>where
A: UnwindSafe,
Blanket Implementations§
Source§impl<A> AlgorithmExt for Awhere
A: Algorithm,
impl<A> AlgorithmExt for Awhere
A: Algorithm,
Source§fn token<T>(
&self,
header: &Header<impl Serialize>,
claims: &Claims<T>,
signing_key: &<A as Algorithm>::SigningKey,
) -> Result<String, CreationError>where
T: Serialize,
fn token<T>(
&self,
header: &Header<impl Serialize>,
claims: &Claims<T>,
signing_key: &<A as Algorithm>::SigningKey,
) -> Result<String, CreationError>where
T: Serialize,
Creates a new token and serializes it to string.
Source§fn validator<'a, T>(
&'a self,
verifying_key: &'a <A as Algorithm>::VerifyingKey,
) -> Validator<'a, A, T>
fn validator<'a, T>( &'a self, verifying_key: &'a <A as Algorithm>::VerifyingKey, ) -> Validator<'a, A, T>
Creates a JWT validator for the specified verifying key and the claims type.
The validator can then be used to validate integrity of one or more tokens.
Source§fn validate_integrity<T>(
&self,
token: &UntrustedToken,
verifying_key: &<A as Algorithm>::VerifyingKey,
) -> Result<Token<T>, ValidationError>where
T: DeserializeOwned,
fn validate_integrity<T>(
&self,
token: &UntrustedToken,
verifying_key: &<A as Algorithm>::VerifyingKey,
) -> Result<Token<T>, ValidationError>where
T: DeserializeOwned,
👎Deprecated: Use
.validator().validate() for added flexibilityValidates the token integrity against the provided
verifying_key.Source§fn validate_for_signed_token<T>(
&self,
token: &UntrustedToken,
verifying_key: &<A as Algorithm>::VerifyingKey,
) -> Result<SignedToken<A, T>, ValidationError>where
T: DeserializeOwned,
fn validate_for_signed_token<T>(
&self,
token: &UntrustedToken,
verifying_key: &<A as Algorithm>::VerifyingKey,
) -> Result<SignedToken<A, T>, ValidationError>where
T: DeserializeOwned,
👎Deprecated: Use
.validator().validate_for_signed_token() for added flexibilityValidates the token integrity against the provided
verifying_key. Read moreSource§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
Mutably borrows from an owned value. Read more
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> 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>
Converts
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>
Converts
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>,
Consume self to return an equivalent value of
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
The counterpart to
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
Consume self to return an equivalent value of
T.