2 unstable releases

0.2.0 Apr 20, 2024
0.1.0 Apr 20, 2024

#1794 in Cryptography

Download history 24/week @ 2024-07-17 59/week @ 2024-07-24 17/week @ 2024-07-31 22/week @ 2024-08-07 5/week @ 2024-08-14 48/week @ 2024-08-21 24/week @ 2024-08-28 37/week @ 2024-09-04 56/week @ 2024-09-11 48/week @ 2024-09-18 38/week @ 2024-09-25 23/week @ 2024-10-02 26/week @ 2024-10-09 21/week @ 2024-10-16 1/week @ 2024-10-23 20/week @ 2024-10-30

72 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–13MB
~181K SLoC