ParsedToken

Struct ParsedToken 

Source
pub struct ParsedToken { /* private fields */ }
Expand description

Parsed token structure for inspection without cryptographic operations

This struct allows you to examine token metadata (purpose, version, footer) without performing expensive cryptographic verification or decryption. Useful for debugging, logging, middleware, and routing decisions.

§Example

use paseto_pq::ParsedToken;

let token = "paseto.pq1.public.ABC123...";
let parsed = ParsedToken::parse(token)?;

println!("Purpose: {}", parsed.purpose()); // "public"
println!("Version: {}", parsed.version()); // "pq1"
println!("Has footer: {}", parsed.has_footer());

// Use for routing decisions
match parsed.purpose() {
    "public" => println!("Public token - needs verification"),
    "local" => println!("Local token - needs decryption"),
    _ => println!("Unsupported token type"),
}

Implementations§

Source§

impl ParsedToken

Source

pub fn parse(token: &str) -> Result<Self, PqPasetoError>

Parse a PASETO token string to extract structural information

This method performs no cryptographic operations - it only parses the token structure to extract metadata. Use this for debugging, logging, middleware, and routing decisions.

§Arguments
  • token - The PASETO token string to parse
§Returns

Returns a ParsedToken containing the token’s structural information, or an error if the token format is invalid.

§Example
use paseto_pq::ParsedToken;

let token = "paseto.pq1.public.ABC123.DEF456.eyJraWQiOiJ0ZXN0In0";
let parsed = ParsedToken::parse(token)?;

assert_eq!(parsed.purpose(), "public");
assert_eq!(parsed.version(), "pq1");
assert!(parsed.has_footer());
Source

pub fn purpose(&self) -> &str

Get the token purpose (“public” for public tokens, “local” for local tokens)

Source

pub fn version(&self) -> &str

Get the token version (currently “pq1”)

Check if the token has a footer

Source

pub fn footer(&self) -> Option<&Footer>

Get the footer, if present

Source

pub fn payload_bytes(&self) -> &[u8]

Get the raw payload bytes (base64-decoded)

Source

pub fn signature_bytes(&self) -> Option<&[u8]>

Get the signature or authentication tag bytes, if present

For public tokens, this is the ML-DSA signature. For local tokens, this is None (auth tag is embedded in payload).

Source

pub fn payload_length(&self) -> usize

Get the length of the payload in bytes

Source

pub fn total_length(&self) -> usize

Get the total length of the token string

Source

pub fn raw_token(&self) -> &str

Get the raw token string

Source

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

Get footer as JSON string, if present

Source

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

Get footer as pretty-printed JSON string, if present

Source

pub fn is_public(&self) -> bool

Check if this is a public token (uses signatures)

Source

pub fn is_local(&self) -> bool

Check if this is a local token (uses symmetric encryption)

Source

pub fn format_summary(&self) -> String

Get token format summary for debugging

Trait Implementations§

Source§

impl Clone for ParsedToken

Source§

fn clone(&self) -> ParsedToken

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 ParsedToken

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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