std::crypto::jwtJSON Web Token encoding and validation.
Encode, decode, and validate JWTs using HMAC or RSA algorithms.
import std::crypto::jwt;
fn main() {
let token = jwt.encode("{\"sub\":\"1234\"}", "secret", "HS256");
if jwt.validate(token, "secret", "HS256") {
let payload = jwt.decode(token, "secret", "HS256");
println(payload);
}
}
algo_to_i32Map an algorithm name (e.g. "HS256") to its integer code for the FFI layer.
encodeEncode a JSON payload into a signed JWT string.
let token = jwt.encode("{\"sub\":\"user1\"}", "my_secret", "HS256");
decodeDecode and verify a JWT, returning its payload as a JSON string.
Panics if the token signature is invalid.
let payload = jwt.decode(token, "my_secret", "HS256");
decode_insecureDecode a JWT without verifying its signature.
Warning: This does not validate the token. Only use for inspecting untrusted tokens when you don't need authenticity.
let payload = jwt.decode_insecure(token);
validateValidate a JWT signature and expiration.
Returns true if the token is valid, false otherwise.
if jwt.validate(token, "my_secret", "HS256") {
println("valid");
}