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