PWT — Protobuf Web Token (Rust)
PWT (Protobuf Web Token) stores JWT-style claims in Protocol Buffers.
It mirrors the Go implementation and uses the same signing algorithms.
Tokens are smaller than JSON JWTs, and parsing is faster thanks to protobuf
serialization. Custom data lives in a protobuf Struct payload.
Why PWT?
- ✅ Smaller tokens via protobuf serialization
- 🚀 Faster parse + verify routines
- 🔒 Uses JWT-compatible signing algorithms (HS256, RS256, EdDSA)
- 🔁 Drop-in JWT-style workflow with typed claims
Installation
The library is imported as pwt:
use ;
PWT is currently in initial development. Releases in the 0.x series may
include documented API changes before the public API is stabilized at 1.0.0.
Quick Start
use ;
use Struct;
let mut body = default;
body.iss = "example".to_string;
body.sub = "user-123".to_string;
body.exp = 1_700_000_000;
let mut payload = default;
payload.fields.insert;
body.payload = Some;
let token = new_with_claims;
let token_str = token.signed_string?;
let parsed = parse?;
println!;
Migrating from JWT
PWT maps directly to standard JWT claims:
| JWT Claim | PWT Field |
|---|---|
iss |
iss |
sub |
sub |
aud |
aud |
exp |
exp |
nbf |
nbf |
iat |
iat |
jti |
jti |
Custom claims should be stored in the protobuf Struct payload.
API Notes
Token::new,Token::new_versioned, andToken::new_with_claimsmirror the Go API and create a token with a protobuf header/body.Token::signed_stringencodes the header, body, and signature using base64url (no padding) in the same format as PWT-Go.Token::parsevalidates the signature and checks time-based claims.
Tests
Contributions are welcome. See CONTRIBUTING.md for the development workflow and SECURITY.md for reporting security issues.
License
Licensed under the MIT License.