Refactor API
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
2024-04-20 13:48:00 +02:00
parent 4e8797d68d
commit 4984027a29
4 changed files with 64 additions and 36 deletions

View File

@@ -10,13 +10,16 @@ Basic usage:
```rust
let claims = ...; // note : claims must be serializable
// Generate a key pair. Public and private key are both serializable
let (pub_key, priv_key) = generate_ec384_keypair().unwrap();
// 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 = sign_jwt(&priv_key, &claims).expect("Failed to sign JWT!");
let jwt = priv_key.sign_jwt(&claims).expect("Failed to sign JWT!");
// Validate signed JWT
let claims_out = validate_jwt::<Claims>(&pub_key, &jwt).expect("Failed to validate JWT!");
let claims_out = pub_key
.validate_jwt::<Claims>(&jwt)
.expect("Failed to validate JWT!");
```