Claims

Struct Claims 

Source
pub struct Claims {
    pub iss: Option<String>,
    pub sub: Option<String>,
    pub aud: Option<String>,
    pub exp: Option<OffsetDateTime>,
    pub nbf: Option<OffsetDateTime>,
    pub iat: Option<OffsetDateTime>,
    pub jti: Option<String>,
    pub kid: Option<String>,
    pub custom: HashMap<String, Value>,
}
Expand description

Claims contained within a token

Fields§

§iss: Option<String>

Token issuer

§sub: Option<String>

Token subject

§aud: Option<String>

Token audience

§exp: Option<OffsetDateTime>

Token expiration time

§nbf: Option<OffsetDateTime>

Token not-before time

§iat: Option<OffsetDateTime>

Token issued-at time

§jti: Option<String>

Token identifier (jti)

§kid: Option<String>

Key identifier

§custom: HashMap<String, Value>

Custom claims (Conflux-specific)

Implementations§

Source§

impl Claims

Source

pub fn new() -> Self

Create a new empty claims set

Source

pub fn set_issuer( &mut self, issuer: impl Into<String>, ) -> Result<(), PqPasetoError>

Set the issuer claim

Source

pub fn set_subject( &mut self, subject: impl Into<String>, ) -> Result<(), PqPasetoError>

Set the subject claim

Source

pub fn set_audience( &mut self, audience: impl Into<String>, ) -> Result<(), PqPasetoError>

Set the audience claim

Source

pub fn set_expiration( &mut self, exp: OffsetDateTime, ) -> Result<(), PqPasetoError>

Set the expiration time

Source

pub fn set_not_before( &mut self, nbf: OffsetDateTime, ) -> Result<(), PqPasetoError>

Set the not-before time

Source

pub fn set_issued_at( &mut self, iat: OffsetDateTime, ) -> Result<(), PqPasetoError>

Set the issued-at time

Source

pub fn set_jti(&mut self, jti: impl Into<String>) -> Result<(), PqPasetoError>

Set the token identifier

Source

pub fn set_kid(&mut self, kid: impl Into<String>) -> Result<(), PqPasetoError>

Set the key identifier

Source

pub fn add_custom( &mut self, key: impl Into<String>, value: impl Serialize, ) -> Result<(), PqPasetoError>

Add a custom claim

Source

pub fn get_custom(&self, key: &str) -> Option<&Value>

Get a custom claim

Source

pub fn validate_time( &self, now: OffsetDateTime, clock_skew_tolerance: Duration, ) -> Result<(), PqPasetoError>

Validate time-based claims

Source

pub fn issuer(&self) -> Option<&str>

Source

pub fn subject(&self) -> Option<&str>

Source

pub fn audience(&self) -> Option<&str>

Source

pub fn expiration(&self) -> Option<OffsetDateTime>

Source

pub fn not_before(&self) -> Option<OffsetDateTime>

Source

pub fn issued_at(&self) -> Option<OffsetDateTime>

Source

pub fn jti(&self) -> Option<&str>

Source

pub fn kid(&self) -> Option<&str>

Source

pub fn to_json_value(&self) -> Value

Convert claims to a JSON value

This method provides easy integration with logging, databases, and tracing systems.

§Example
use paseto_pq::Claims;
use serde_json::Value;

let mut claims = Claims::new();
claims.set_subject("user123").unwrap();
claims.add_custom("role", "admin").unwrap();

let json_value: Value = claims.to_json_value();
println!("Claims as JSON: {}", json_value);
Source

pub fn to_json_string(&self) -> Result<String, Error>

Convert claims to a JSON string

This method provides easy integration with logging, databases, and tracing systems.

§Example
use paseto_pq::Claims;

let mut claims = Claims::new();
claims.set_subject("user123").unwrap();
claims.add_custom("role", "admin").unwrap();

let json_string = claims.to_json_string().unwrap();
println!("User claims: {}", json_string);
Source

pub fn to_json_string_pretty(&self) -> Result<String, Error>

Convert claims to a pretty-printed JSON string

Useful for debugging and development environments.

§Example
use paseto_pq::Claims;

let mut claims = Claims::new();
claims.set_subject("user123").unwrap();
claims.add_custom("role", "admin").unwrap();

let pretty_json = claims.to_json_string_pretty().unwrap();
println!("Claims:\n{}", pretty_json);

Trait Implementations§

Source§

impl Clone for Claims

Source§

fn clone(&self) -> Claims

Returns a duplicate 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 Debug for Claims

Source§

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

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

impl Default for Claims

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Claims

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 From<&Claims> for Value

Convert &Claims to serde_json::Value (borrowed version)

Source§

fn from(claims: &Claims) -> Self

Converts to this type from the input type.
Source§

impl From<Claims> for Value

Convert Claims to serde_json::Value for easy integration with logging, databases, and tracing

§Example

use paseto_pq::Claims;
use serde_json::Value;

let mut claims = Claims::new();
claims.set_subject("user123").unwrap();
claims.add_custom("tenant_id", "org_abc123").unwrap();

// Direct conversion
let json_value: Value = claims.into();

// Use in logging
println!("User authenticated with claims: {}", json_value);

// Use in database operations
// db.insert_audit_log(json_value).await?;
Source§

fn from(claims: Claims) -> Self

Converts to this type from the input type.
Source§

impl Serialize for Claims

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

Auto Trait Implementations§

§

impl Freeze for Claims

§

impl RefUnwindSafe for Claims

§

impl Send for Claims

§

impl Sync for Claims

§

impl Unpin for Claims

§

impl UnwindSafe for Claims

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§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

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