Struct JwtSecret
pub struct JwtSecret(/* private fields */);
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§
§impl JwtSecret
impl JwtSecret
pub fn from_hex<S>(hex: S) -> Result<JwtSecret, JwtError>
pub fn from_hex<S>(hex: S) -> Result<JwtSecret, 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.
pub fn try_create_random(fpath: &Path) -> Result<JwtSecret, JwtError>
Available on crate feature std
only.
pub fn try_create_random(fpath: &Path) -> Result<JwtSecret, JwtError>
std
only.pub 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
pub fn random() -> JwtSecret
pub fn random() -> JwtSecret
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where
S: Into<Dispatch>,
§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> MaybeSend for Twhere
T: Send,
impl<T> MaybeSendSync for T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes