std::crypto::jwtJSON Web Token encoding and validation.
Encode, decode, and validate JWTs using HMAC algorithms.
import std::crypto::jwt;
fn main() {
match jwt.try_encode("{\"sub\":\"1234\"}", "secret", "HS256") {
Ok(token) => println(token),
Err(err) => println(jwt.error_message(err)),
}
}
error_messageReturn a human-readable message for a [JwtError].
last_errorReturn the last JWT error observed on this thread.
try_encodeEncode a JSON payload into a signed JWT string.
Returns Err(JwtError) when the payload, key, algorithm, or allocation
path fails.
encodeEncode a JSON payload into a signed JWT string.
Panics on invalid input or verification setup errors. Use try_encode for
structured error handling.
try_decodeDecode and verify a JWT, returning its payload as a JSON string.
Returns Err(JwtError) when the token is malformed, expired, signed with a
different key, or cannot be allocated.
decodeDecode and verify a JWT, returning its payload as a JSON string.
Panics on invalid tokens. Use try_decode for structured error handling.
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");
}
JwtErrorStructured JWT errors surfaced by the native C ABI.
NoneAlgorithmUnsupportedInvalidKeyTokenMalformedSignatureInvalidClaimsExpiredAllocationFailure