Module jwk

Module jwk 

Source
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§

RsaPrimeFactor
Block for an additional prime factor in RsaPrivateParts.
RsaPrivateParts
Parts of JsonWebKey::Rsa that are specific to private keys.

Enums§

JsonWebKey
Basic JWK functionality: (de)serialization and creating thumbprints.
JwkError
Errors that can occur when transforming a JsonWebKey into the presentation specific for a crypto backend, using the TryFrom trait.
KeyType
Type of a JsonWebKey.