Expand description
Basic support of JSON Web Keys (JWK).
The functionality defined in this module allows converting between
the generic JWK format and key presentation specific for the crypto backend.
JsonWebKeys can be (de)serialized using serde infrastructure, and can be used
to compute key thumbprint as per RFC 7638.
§Examples
use jwt_compact::{alg::Hs256Key, jwk::JsonWebKey};
use sha2::Sha256;
// Load a key from the JWK presentation.
let json_str = r#"
{ "kty": "oct", "k": "t-bdv41MJXExXnpquHBuDn7n1YGyX7gLQchVHAoNu50" }
"#;
let jwk: JsonWebKey<'_> = serde_json::from_str(json_str)?;
let key = Hs256Key::try_from(&jwk)?;
// Convert `key` back to JWK.
let jwk_from_key = JsonWebKey::from(&key);
assert_eq!(jwk_from_key, jwk);
println!("{}", serde_json::to_string(&jwk)?);
// Compute the key thumbprint.
let thumbprint = jwk_from_key.thumbprint::<Sha256>();Structs§
- RsaPrime
Factor - Block for an additional prime factor in
RsaPrivateParts. - RsaPrivate
Parts - Parts of
JsonWebKey::Rsathat are specific to private keys.
Enums§
- Json
WebKey - Basic JWK functionality: (de)serialization and creating thumbprints.
- JwkError
- Errors that can occur when transforming a
JsonWebKeyinto the presentation specific for a crypto backend, using theTryFromtrait. - KeyType
- Type of a
JsonWebKey.