2 unstable releases

0.2.0 Apr 20, 2024
0.1.0 Apr 20, 2024

#1497 in Cryptography

Download history 61/week @ 2024-05-17 47/week @ 2024-05-24 20/week @ 2024-05-31 51/week @ 2024-06-07 29/week @ 2024-06-14 47/week @ 2024-06-21 80/week @ 2024-06-28 57/week @ 2024-07-05 33/week @ 2024-07-12 39/week @ 2024-07-19 42/week @ 2024-07-26 19/week @ 2024-08-02 13/week @ 2024-08-09 12/week @ 2024-08-16 46/week @ 2024-08-23 23/week @ 2024-08-30

98 downloads per month

MIT license

8KB
144 lines

Basic JWT

This crate provide basic functions to:

  • Sign JWT
  • Parse and validate JWT

Basic usage:

let claims = ...; // note : claims must be serializable

// Generate a key pair. Private and public key are both serializable
let priv_key = JWTPrivateKey::generate_ec384_signing_key().unwrap();
let pub_key = priv_key.to_public_key().unwrap();

// Create a JWT for the given claims (note: standard claims: sub, iss, ...) are not
// automatically added if they are missing
let jwt = priv_key.sign_jwt(&claims).expect("Failed to sign JWT!");

// Validate signed JWT
let claims_out = pub_key
            .validate_jwt::<Claims>(&jwt)
            .expect("Failed to validate JWT!");

Dependencies

~5–14MB
~183K SLoC