1
0
mirror of https://github.com/BitskiCo/jwk-rs synced 2024-11-25 05:19:22 +00:00
jwk-rs/README.md

46 lines
1.7 KiB
Markdown
Raw Normal View History

2020-07-12 18:57:57 +00:00
# jsonwebkey
2020-07-12 21:23:06 +00:00
*[JSON Web Key (JWK)](https://tools.ietf.org/html/rfc7517#section-4.3) (de)serialization, generation, and conversion.*
2020-07-12 18:57:57 +00:00
2020-07-12 21:23:06 +00:00
Note: requires rustc nightly >= 1.45 for conveniences around fixed-size arrays.
**Goals**
tl;dr: get keys into a format that can be used by other crates; be as safe as possible while doing so.
2020-07-12 18:57:57 +00:00
- [x] Serialization and deserialization of _Required_ and _Recommended_ key types (HS256, RS256, ES256)
2020-07-12 21:23:06 +00:00
- [x] Conversion to PEM for interop with existing JWT libraries (e.g., [jsonwebtoken](https://crates.io/crates/jsonwebtoken))
2020-07-12 18:57:57 +00:00
- [ ] Key generation (particularly for testing)
2020-07-12 21:23:06 +00:00
**Non-goals**
* be a fully-featured JOSE framework
## Example
```rust
extern crate jsonwebtoken as jwt;
extern crate jsonwebkey as jwk;
fn main() {
let jwk_str = r#"{
"kty": "EC",
"d": "ZoKQ9j4dhIBlMRVrv-QG8P_T9sutv3_95eio9MtpgKg",
"crv": "P-256",
"x": "QOMHmv96tVlJv-uNqprnDSKIj5AiLTXKRomXYnav0N0",
"y": "TjYZoHnctatEE6NCrKmXQdJJPnNzZEX8nBmZde3AY4k"
}"#;
let jwk = jwk::JsonWebKey::from_str(jwk_str).unwrap();
let encoding_key = jwk::EncodingKey::from_ec_der(jwk.to_der().unwrap());
let token = jwt::encode(&jwt::Header::default(), &() /* claims */, encoding_key).unwrap();
}
```
2020-07-13 20:46:42 +00:00
## Features
* `convert` - enables `Key::{to_der, to_pem}`.
This pulls in the [yasna](https://crates.io/crates/yasna) crate.
2020-07-13 23:07:02 +00:00
* `generate` - enables `Key::{generate_p256, generate_symmetric}`.
This pulls in the [p256](https://crates.io/crates/p256) and [rand](https://crates.io/crates/rand) crates.
2020-07-13 22:11:10 +00:00
* `jsonwebtoken` - enables conversions to types in the [jsonwebtoken](https://crates.io/crates/jsonwebtoken) crate.