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> Algorithm for Renamed<A>
impl<A: Algorithm> Algorithm for Renamed<A>
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§fn sign(
&self,
signing_key: &Self::SigningKey,
message: &[u8],
) -> Self::Signature
fn sign( &self, signing_key: &Self::SigningKey, message: &[u8], ) -> Self::Signature
Signs a
message with the signing_key.Source§fn verify_signature(
&self,
signature: &Self::Signature,
verifying_key: &Self::VerifyingKey,
message: &[u8],
) -> bool
fn verify_signature( &self, signature: &Self::Signature, verifying_key: &Self::VerifyingKey, message: &[u8], ) -> bool
Verifies the
message against the signature and verifying_key.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: Output + ?Sized>(
&self,
__codec_dest_edqy: &mut __CodecOutputEdqy,
)
fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &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> Copy for Renamed<A>
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 compact_token<T>(
&self,
header: &Header<impl Serialize>,
claims: &Claims<T>,
signing_key: &<A as Algorithm>::SigningKey,
) -> Result<String, CreationError>where
T: Serialize,
fn compact_token<T>(
&self,
header: &Header<impl Serialize>,
claims: &Claims<T>,
signing_key: &<A as Algorithm>::SigningKey,
) -> Result<String, CreationError>where
T: Serialize,
Available on crate feature
ciborium only.Creates a new token with CBOR-encoded claims 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