Skip to content

docs(parser): clarify expiration validation behavior in PasetoParser#69

Merged
rrrodzilla merged 1 commit into
mainfrom
docs/parser-expiration-validation
Oct 5, 2025
Merged

docs(parser): clarify expiration validation behavior in PasetoParser#69
rrrodzilla merged 1 commit into
mainfrom
docs/parser-expiration-validation

Conversation

@rrrodzilla

Copy link
Copy Markdown
Owner

Summary

Adds explicit documentation that PasetoParser::default() automatically validates expiration and not-before claims, addressing user confusion reported in issue #26.

Changes

  • README: Added new "Validating tokens and handling errors" section with practical example
  • src/lib.rs: Updated parser documentation with automatic validation details
  • src/prelude/paseto_parser.rs: Enhanced struct-level and method documentation

Key Documentation Additions

  1. Default behavior clarification: PasetoParser::default() validates exp and nbf claims automatically
  2. Alternative constructor: PasetoParser::new() creates parser without automatic time-based validations
  3. Error handling example: Demonstrates token validation with expired token error handling
  4. Return value documentation: Explicitly documents GenericParserError return for validation failures

Example Added

use rusty_paseto::prelude::*;

let key = PasetoSymmetricKey::<V4, Local>::from(Key::from(b"wubbalubbadubdubwubbalubbadubdub"));

// Create a token that expires in the past
let token = PasetoBuilder::<V4, Local>::default()
  .set_claim(ExpirationClaim::try_from("2019-01-01T00:00:00+00:00")?)
  .build(&key)?;

// Parsing the expired token returns an error
match PasetoParser::<V4, Local>::default().parse(&token, &key) {
  Ok(json_value) => {
    println!("Token valid: {}", json_value);
  }
  Err(err) => {
    // This will print: "This token is expired"
    eprintln!("Token validation failed: {}", err);
  }
}

Testing

  • Verified code compiles with cargo build --no-default-features --features v4_local
  • Checked clippy passes with zero warnings: cargo clippy --all-targets -- -D warnings
  • Formatted code with cargo fmt

Closes #26

Add explicit documentation that PasetoParser::default() automatically validates
expiration and not-before claims. Include example showing error handling for
expired tokens.

Changes:
- Update README with new "Validating tokens and handling errors" section
- Clarify PasetoParser::default() validates exp and nbf claims automatically
- Document that PasetoParser::new() creates parser without automatic validations
- Add example demonstrating error handling for expired tokens
- Update struct-level and method documentation for clarity

Closes #26
@rrrodzilla
rrrodzilla marked this pull request as ready for review October 5, 2025 22:04
@rrrodzilla
rrrodzilla merged commit 10c3116 into main Oct 5, 2025
38 checks passed
@rrrodzilla
rrrodzilla deleted the docs/parser-expiration-validation branch October 5, 2025 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs PasetoParser::<V4, Local>

1 participant