pub struct Claims<T> {
pub expiration: Option<DateTime<Utc>>,
pub not_before: Option<DateTime<Utc>>,
pub issued_at: Option<DateTime<Utc>>,
pub custom: T,
}Expand description
Claims encoded in a token.
Claims are comprised of a “standard” part (exp, nbf and iat claims as per JWT spec),
and custom fields. iss, sub and aud claims are not in the standard part
due to a variety of data types they can be reasonably represented by.
Fields§
§expiration: Option<DateTime<Utc>>Expiration time of the token.
not_before: Option<DateTime<Utc>>Minimum time at which token is valid.
issued_at: Option<DateTime<Utc>>Time of token issuance.
custom: TCustom claims.
Implementations§
Source§impl<T> Claims<T>
impl<T> Claims<T>
Sourcepub const fn new(custom_claims: T) -> Claims<T>
pub const fn new(custom_claims: T) -> Claims<T>
Creates a new instance with the provided custom claims.
Sourcepub fn set_duration<F>(
self,
options: &TimeOptions<F>,
duration: TimeDelta,
) -> Claims<T>
pub fn set_duration<F>( self, options: &TimeOptions<F>, duration: TimeDelta, ) -> Claims<T>
Sets the expiration claim so that the token has the specified duration.
The current timestamp is taken from options.
Sourcepub fn set_duration_and_issuance<F>(
self,
options: &TimeOptions<F>,
duration: TimeDelta,
) -> Claims<T>
pub fn set_duration_and_issuance<F>( self, options: &TimeOptions<F>, duration: TimeDelta, ) -> Claims<T>
Atomically sets issued_at and expiration claims: first to the current time
(taken from options), and the second to match the specified duration of the token.
Sourcepub fn set_not_before(self, moment: DateTime<Utc>) -> Claims<T>
pub fn set_not_before(self, moment: DateTime<Utc>) -> Claims<T>
Sets the nbf claim.
Sourcepub fn validate_expiration<F>(
&self,
options: &TimeOptions<F>,
) -> Result<&Claims<T>, ValidationError>
pub fn validate_expiration<F>( &self, options: &TimeOptions<F>, ) -> Result<&Claims<T>, ValidationError>
Validates the expiration claim.
This method will return an error if the claims do not feature an expiration time,
or if it is in the past (subject to the provided options).
Sourcepub fn validate_maturity<F>(
&self,
options: &TimeOptions<F>,
) -> Result<&Claims<T>, ValidationError>
pub fn validate_maturity<F>( &self, options: &TimeOptions<F>, ) -> Result<&Claims<T>, ValidationError>
Validates the maturity time (nbf claim).
This method will return an error if the claims do not feature a maturity time,
or if it is in the future (subject to the provided options).
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Claims<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Claims<T>where
T: Deserialize<'de>,
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Claims<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Claims<T>, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl<T> Ord for Claims<T>where
T: Ord,
impl<T> Ord for Claims<T>where
T: Ord,
Source§impl<T> PartialOrd for Claims<T>where
T: PartialOrd,
impl<T> PartialOrd for Claims<T>where
T: PartialOrd,
Source§impl<T> Serialize for Claims<T>where
T: Serialize,
impl<T> Serialize for Claims<T>where
T: Serialize,
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl<T> Eq for Claims<T>where
T: Eq,
impl<T> StructuralPartialEq for Claims<T>
Auto Trait Implementations§
impl<T> Freeze for Claims<T>where
T: Freeze,
impl<T> RefUnwindSafe for Claims<T>where
T: RefUnwindSafe,
impl<T> Send for Claims<T>where
T: Send,
impl<T> Sync for Claims<T>where
T: Sync,
impl<T> Unpin for Claims<T>where
T: Unpin,
impl<T> UnwindSafe for Claims<T>where
T: UnwindSafe,
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> 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> DefensiveMax<T> for Twhere
T: PartialOrd,
impl<T> DefensiveMax<T> for Twhere
T: PartialOrd,
Source§fn defensive_max(self, other: T) -> T
fn defensive_max(self, other: T) -> T
Source§fn defensive_strict_max(self, other: T) -> T
fn defensive_strict_max(self, other: T) -> T
Source§impl<T> DefensiveMin<T> for Twhere
T: PartialOrd,
impl<T> DefensiveMin<T> for Twhere
T: PartialOrd,
Source§fn defensive_min(self, other: T) -> T
fn defensive_min(self, other: T) -> T
Source§fn defensive_strict_min(self, other: T) -> T
fn defensive_strict_min(self, other: T) -> T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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>
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 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>,
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
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
T.