[−][src]Struct jsonwebtokens::Algorithm
A cryptographic function for signing or verifying a token signature
An Algorithm encapsulates one function for signing or verifying tokens. A key
or secret only needs to be decoded once so it can be reused cheaply while
signing or verifying tokens. The decoded key or secret and AlgorithmID
are
immutable after construction to avoid the chance of being coerced into using
the wrong algorithm to sign or verify a token at runtime.
Optionally a kid
Key ID can be assigned to an Algorithm
to add a strict
check that a token's header must include the same kid
value. This is useful
when using an Algorithm
to represent a single key within a JWKS key set,
for example.
Methods
impl Algorithm
[src]
pub fn id(&self) -> AlgorithmID
[src]
Returns the AlgorithmID
that was used to construct the Algorithm
pub fn name(&self) -> &'static str
[src]
Returns the algorithm name as standardized in RFC 7518
pub fn set_kid(&mut self, kid: impl Into<String>)
[src]
Optionally if a kid
is associated with an algorithm there will be an extra
verification that a token's kid matches the one associated with the Algorithm
pub fn kid(&self) -> Option<&str>
[src]
Returns a reference to any associated kid
set via set_kid()
pub fn new_unsecured() -> Result<Self, Error>
[src]
Constructs a NOP algorithm for use with unsecured (unsigned) tokens
pub fn new_hmac(
id: AlgorithmID,
secret: impl Into<Vec<u8>>
) -> Result<Self, Error>
[src]
id: AlgorithmID,
secret: impl Into<Vec<u8>>
) -> Result<Self, Error>
Constructs a symmetric HMAC algorithm based on a given secret
This algorithm may be used for signing and/or verifying signatures
pub fn new_hmac_b64(
id: AlgorithmID,
secret: impl AsRef<str>
) -> Result<Self, Error>
[src]
id: AlgorithmID,
secret: impl AsRef<str>
) -> Result<Self, Error>
Constructs a symmetric HMAC algorithm based on a given base64 secret
This is a convenience api in case the secret you're using is base64 encoded
This algorithm may be used for signing and/or verifying signatures
pub fn new_ecdsa_pem_signer(id: AlgorithmID, key: &[u8]) -> Result<Self, Error>
[src]
Constructs an ECDSA algorithm based on a PEM format private key
This algorithm may only be used for signing tokens
pub fn new_ecdsa_pem_verifier(
id: AlgorithmID,
key: &[u8]
) -> Result<Self, Error>
[src]
id: AlgorithmID,
key: &[u8]
) -> Result<Self, Error>
Constructs an ECDSA algorithm based on a PEM format public key
This algorithm may only be used for verifying tokens
pub fn new_rsa_pem_signer(id: AlgorithmID, key: &[u8]) -> Result<Self, Error>
[src]
Constructs an RSA algorithm based on a PEM format private key
This algorithm may only be used for signing tokens
pub fn new_rsa_pem_verifier(id: AlgorithmID, key: &[u8]) -> Result<Self, Error>
[src]
Constructs an RSA algorithm based on a PEM format public key
This algorithm may only be used for verifying tokens
pub fn new_rsa_n_e_b64_verifier(
id: AlgorithmID,
n_b64: &str,
e_b64: &str
) -> Result<Self, Error>
[src]
id: AlgorithmID,
n_b64: &str,
e_b64: &str
) -> Result<Self, Error>
Constructs an RSA algorithm based on modulus (n) and exponent (e) components
In some situations (such as JWKS key sets), a public RSA key may be described in terms of (base64 encoded) modulus and exponent values.
This algorithm may only be used for verifying tokens
pub fn verify(
&self,
kid: Option<&str>,
message: impl AsRef<str>,
signature: impl AsRef<str>
) -> Result<(), Error>
[src]
&self,
kid: Option<&str>,
message: impl AsRef<str>,
signature: impl AsRef<str>
) -> Result<(), Error>
Lower-level api that can be used to verify a signature for a given message
pub fn sign(&self, message: &str) -> Result<String, Error>
[src]
Lower-level api that can be used to calculate a signature for a message
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Algorithm
impl Send for Algorithm
impl Sync for Algorithm
impl Unpin for Algorithm
impl UnwindSafe for Algorithm
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,