1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! JSON Object Signing and Encryption: keys, algorithms, signature verification and the compact
//! JWS serialization.
//!
//! This is the crate's signature layer. Everything above it (DID documents, credentials) carries a
//! [`Jwk`] and a [`JwsAlgorithm`] and hands signing input to a [`JwsVerifier`] or a [`Signer`]:
//!
//! - [`Jwk`] is a JSON Web Key (RFC 7517), kept as the JSON it arrived as, with RFC 7638
//! thumbprints, raw public key accessors for Ed25519, X25519, P-256 and secp256k1, and
//! conversion to and from a Multikey string ([`Jwk::from_multikey`], [`Jwk::to_multikey`]).
//! - [`JwsAlgorithm`] names the asymmetric algorithms this crate speaks and converts to and from
//! [`jsonwebtoken::Algorithm`].
//! - [`JwsVerifier`] verifies a signature over a signing input; [`DefaultVerifier`] does so with
//! RustCrypto. ECDSA signatures are the raw `r || s` form JWS uses, never DER. An ES256
//! signature verifies with `s` and `n - s` alike, so identify a token by its claims, not its
//! bytes (see [`DefaultVerifier`]).
//! - [`CompactJws`] decodes a compact serialization without verifying it; [`encode_compact`]
//! produces one with any [`Signer`], which is `async` because private keys live in key stores
//! and HSMs.
//! - [`ecdsa_signature_from_der`] and [`normalize_ecdsa_signature`] turn what an HSM or a cloud
//! KMS returns for an ECDSA key into the JWS form: raw `r || s`, with a secp256k1 `s` in the
//! lower half of the group order.
//! - [`JwtClaims`] is a JWT claims set (RFC 7519): the registered claims as fields, `aud` as a
//! [`OneOrMany`], times as `NumericDate` seconds, every other claim kept in order.
//! [`CompactJws::claims`] reads a payload as one, unverified; `JwtValidator` of
//! [`resolver`](crate::resolver) validates one, its signer's key resolved by a `KeyResolver`.
//!
//! JWE is out of scope.
//!
//! # Cargo features
//!
//! - `secp256k1` (default): ES256K and secp256k1 keys, via `k256`.
//! - `rsa`: RS256 and PS256, via `rsa`, with keys of at least 2048 bits (RFC 7518 §3.3,
//! §3.5).
pub
pub use ;
pub use JwtClaims;
pub use numeric_date;
pub use ;
pub use ;
pub use ;
pub use ;
pub use KeyCodec;
pub use OneOrMany;
pub use ;