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
impl ParsedToken
Sourcepub fn parse(token: &str) -> Result<Self, PqPasetoError>
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());Sourcepub fn purpose(&self) -> &str
pub fn purpose(&self) -> &str
Get the token purpose (“public” for public tokens, “local” for local tokens)
Check if the token has a footer
Get the footer, if present
Sourcepub fn payload_bytes(&self) -> &[u8] ⓘ
pub fn payload_bytes(&self) -> &[u8] ⓘ
Get the raw payload bytes (base64-decoded)
Sourcepub fn signature_bytes(&self) -> Option<&[u8]>
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).
Sourcepub fn payload_length(&self) -> usize
pub fn payload_length(&self) -> usize
Get the length of the payload in bytes
Sourcepub fn total_length(&self) -> usize
pub fn total_length(&self) -> usize
Get the total length of the token string
Get footer as JSON string, if present
Get footer as pretty-printed JSON string, if present
Sourcepub fn format_summary(&self) -> String
pub fn format_summary(&self) -> String
Get token format summary for debugging
Trait Implementations§
Source§impl Clone for ParsedToken
impl Clone for ParsedToken
Source§fn clone(&self) -> ParsedToken
fn clone(&self) -> ParsedToken
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more