Pure Rust implementation of the JSON Web Key ([JWK]) component of the Javascript Object Signing and Encryption ([JOSE]) specification as described in [RFC7517].
A JWK is a way to represent cryptographic keys in JSON, typically public keys. This format contains information about how the key needs to be used so a child node can validate what a parent node sends (e.g. with JWTs) or encrypt messages for the parent node using this key (e.g. with JWEs). This crate provides data structures to interface with this format.
```rust use josejwk::{Jwk, JwkSet, Key}; use josejwk::jose_jwa::{Algorithm, Signing};
let keys = serdejson::json!({ "keys": [ { "kty": "EC", "crv": "P-256", "x": "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4", "y": "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM", "use": "enc", "kid": "some-ec-kid" }, { "kty": "RSA", "n": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx4cbbfAAtV\ T86zwu1RK7aPFFxuhDR1L6tSocBJECPebWKRXjBZCiFV4n3oknjhMstn64tZ2W-5\ JsGY4Hc5n9yBXArwl93lqt7RN5w6Cf0h4QyQ5v-65YGjQR0FDW2QvzqY368QQMic\ AtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbISD08qNLyrdkt-bF\ TWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-GxBniIqbw0Ls1jF44-csFCur-\ kEgU8awapJzKnqDKgw", "e": "AQAB", "alg": "RS256", "kid": "some-rsa-kid" } ] });
let jwkset: JwkSet = serdejson::fromvalue(keys).unwrap(); let ecjwk: &Jwk = &jwkset.keys[0]; let rsajwk: &Jwk = &jwkset.keys[1];
assert!(matches!(ecjwk.key, Key::Ec())); assert!(matches!(rsajwk.key, Key::Rsa()));
asserteq!(ecjwk.prm.kid, Some(String::from("some-ec-kid"))); asserteq!(rsajwk.prm.kid, Some(String::from("some-rsa-kid")));
asserteq!(rsajwk.prm.alg, Some(Algorithm::Signing(Signing::Rs256))); ```
This crate requires Rust 1.65 at a minimum.
We may change the MSRV in the future, but it will be accompanied by a minor version bump.
Licensed under either of:
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.