2个不稳定版本
0.2.0 | 2024年4月20日 |
---|---|
0.1.0 | 2024年4月20日 |
#1282 in 加密
每月下载量160
8KB
144 行
Basic JWT
此crate提供以下基本功能:
- 签名JWT
- 解析和验证JWT
基本用法
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!");
依赖项
~5–14MB
~179K SLoC