jwt_lab/
lib.rs

1//! # jwt-lab
2//!
3//! A production-grade JWT (JSON Web Token) crate for Rust with comprehensive
4//! support for decoding, verifying, signing, and mutating JWTs.
5//!
6//! ## Features
7//!
8//! - **Multiple Algorithms**: HS256/384/512, RS256/384/512, ES256/384/512, EdDSA
9//! - **JWK/JWKS Support**: Verify tokens using JSON Web Key Sets
10//! - **Algorithm Validation**: Prevent algorithm confusion attacks
11//! - **Time Validation**: Configurable leeway for `exp` and `nbf` claims
12//! - **Claims Mutation**: Modify JWT claims using JSON pointer paths
13//! - **Feature Flags**: Fine-grained control over included algorithms
14//! - **Strong Error Types**: Comprehensive error handling with clear messages
15//!
16//! ## Quick Start
17//!
18//! ```rust
19//! use jwt_lab::{Algorithm, Header, Claims, Key};
20//! use jwt_lab::sign::sign;
21//! use serde_json::json;
22//!
23//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
24//! // Create and sign a JWT
25//! let header = Header {
26//!     alg: Algorithm::HS256,
27//!     typ: Some("JWT".into()),
28//!     kid: None,
29//!     extra: Default::default()
30//! };
31//! let claims = Claims(serde_json::from_value(json!({
32//!     "sub": "user123",
33//!     "iat": 1516239022
34//! }))?);
35//! let token = sign(&header, &claims, &Key::hs("secret"))?;
36//! println!("Generated token: {}", token);
37//! # Ok(()) }
38//! ```
39//!
40//! ## Security Considerations
41//!
42//! - Always validate the algorithm to prevent algorithm confusion attacks
43//! - Set appropriate expiration times and use minimal leeway
44//! - Validate issuer and audience claims when possible
45//! - Never accept tokens with `alg: "none"`
46
47mod errors;
48mod types;
49mod b64;
50mod time;
51mod decode;
52/// JWT signing functionality
53pub mod sign;
54mod verify;
55mod mutate;
56mod jwk;
57
58pub use errors::{Error, Result};
59pub use types::{Algorithm, Header, Claims, Jwt};
60pub use verify::VerifyOptions;
61pub use jwk::{Jwk, Jwks, Key, KeySource};
62
63#[cfg(feature = "explain")]
64pub use types::Explanation;