Struct jwt_compact::Claims

source ·
#[non_exhaustive]
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 (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§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: T

Custom claims.

Implementations§

source§

impl Claims<Empty>

source

pub fn empty() -> Self

Creates an empty claims instance.

source§

impl<T> Claims<T>

source

pub fn new(custom_claims: T) -> Self

Creates a new instance with the provided custom claims.

source

pub fn set_duration<F>( self, options: &TimeOptions<F>, duration: Duration, ) -> Self
where F: Fn() -> DateTime<Utc>,

Sets the expiration claim so that the token has the specified duration. The current timestamp is taken from options.

source

pub fn set_duration_and_issuance<F>( self, options: &TimeOptions<F>, duration: Duration, ) -> Self
where F: Fn() -> DateTime<Utc>,

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.

source

pub fn set_not_before(self, moment: DateTime<Utc>) -> Self

Sets the nbf claim.

source

pub fn validate_expiration<F>( &self, options: &TimeOptions<F>, ) -> Result<&Self, ValidationError>
where F: Fn() -> DateTime<Utc>,

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).

source

pub fn validate_maturity<F>( &self, options: &TimeOptions<F>, ) -> Result<&Self, ValidationError>
where F: Fn() -> DateTime<Utc>,

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<T: Clone> Clone for Claims<T>

source§

fn clone(&self) -> Claims<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Claims<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, T> Deserialize<'de> for Claims<T>
where T: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<T: PartialEq> PartialEq for Claims<T>

source§

fn eq(&self, other: &Claims<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Serialize for Claims<T>
where T: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<T: Eq> Eq for Claims<T>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,