pub struct JwtSecret(/* private fields */);
Available on crate feature
jwt
only.Expand description
Value-object holding a reference to a hex-encoded 256-bit secret key.
A JWT secret key is used to secure JWT-based authentication. The secret key is a shared secret between the server and the client and is used to calculate a digital signature for the JWT, which is included in the JWT along with its payload.
See also: Secret key - Engine API specs
Implementations§
source§impl JwtSecret
impl JwtSecret
sourcepub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self, JwtError>
pub fn from_hex<S: AsRef<str>>(hex: S) -> Result<Self, JwtError>
Creates an instance of JwtSecret
.
Returns an error if one of the following applies:
hex
is not a valid hexadecimal stringhex
argument length is less thanJWT_SECRET_LEN
This strips the leading 0x
, if any.
sourcepub fn try_create_random(fpath: &Path) -> Result<Self, JwtError>
Available on crate feature std
only.
pub fn try_create_random(fpath: &Path) -> Result<Self, JwtError>
std
only.sourcepub fn validate(&self, jwt: &str) -> Result<(), JwtError>
Available on crate feature serde
only.
pub fn validate(&self, jwt: &str) -> Result<(), JwtError>
serde
only.Validates a JWT token along the following rules:
- The JWT signature is valid.
- The JWT is signed with the
HMAC + SHA256 (HS256)
algorithm. - The JWT
iat
(issued-at) claim is a timestamp within +-60 seconds from the current time. - The JWT
exp
(expiration time) claim is validated by default if defined.
See also: JWT Claims - Engine API specs
sourcepub fn random() -> Self
pub fn random() -> Self
Generates a random JwtSecret
containing a hex-encoded 256 bit secret key.
Trait Implementations§
impl Copy for JwtSecret
impl Eq for JwtSecret
impl StructuralPartialEq for JwtSecret
Auto Trait Implementations§
impl Freeze for JwtSecret
impl RefUnwindSafe for JwtSecret
impl Send for JwtSecret
impl Sync for JwtSecret
impl Unpin for JwtSecret
impl UnwindSafe for JwtSecret
Blanket Implementations§
source§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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 more