Expand description
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:
Jwkis 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).JwsAlgorithmnames the asymmetric algorithms this crate speaks and converts to and fromjsonwebtoken::Algorithm.JwsVerifierverifies a signature over a signing input;DefaultVerifierdoes so with RustCrypto. ECDSA signatures are the rawr || sform JWS uses, never DER. An ES256 signature verifies withsandn - salike, so identify a token by its claims, not its bytes (seeDefaultVerifier).CompactJwsdecodes a compact serialization without verifying it;encode_compactproduces one with anySigner, which isasyncbecause private keys live in key stores and HSMs.ecdsa_signature_from_derandnormalize_ecdsa_signatureturn what an HSM or a cloud KMS returns for an ECDSA key into the JWS form: rawr || s, with a secp256k1sin the lower half of the group order.JwtClaimsis a JWT claims set (RFC 7519): the registered claims as fields,audas aOneOrMany, times asNumericDateseconds, every other claim kept in order.CompactJws::claimsreads a payload as one, unverified;JwtValidatorofresolvervalidates one, its signer’s key resolved by aKeyResolver.
JWE is out of scope.
§Cargo features
secp256k1(default): ES256K and secp256k1 keys, viak256.rsa: RS256 and PS256, viarsa, with keys of at least 2048 bits (RFC 7518 §3.3, §3.5).
Structs§
- Compact
Jws - A decoded compact JWS:
BASE64URL(header) || '.' || BASE64URL(payload) || '.' || BASE64URL(signature). - Default
Verifier - A
JwsVerifierover RustCrypto:ed25519-dalekfor EdDSA,p256for ES256,k256for ES256K (featuresecp256k1) andrsafor RS256 and PS256 (featurersa). - Jwk
- A JSON Web Key (RFC 7517).
- JwsHeader
- The JOSE header of a JWS (RFC 7515 §4).
- JwtClaims
- A JWT claims set: the registered claims of RFC 7519 §4.1 as fields, every other claim
(
vc,vp,nonce,cnf, …) inadditional. - Sign
Error - An error from a
Signer. - Unknown
Algorithm - An algorithm name that is not a
JwsAlgorithm.
Enums§
- Ecdsa
Signature Error - Why an ECDSA signature cannot be put in its JWS form; see
ecdsa_signature_from_derandnormalize_ecdsa_signature. - JwkError
- Why a
Jwkcannot be built, or cannot be used the way it was asked to. - JwsAlgorithm
- A JWS digital signature algorithm (RFC 7518 §3.1, RFC 8037 §3.1, RFC 8812 §3.2).
- JwsError
- Why a compact JWS could not be decoded or produced.
- KeyCodec
- The multicodec codes of the public key types this crate reads from and writes to a Multikey.
- KeyType
- The kind of key behind a
Jwk, as a key store or HSM names it. - OneOr
Many - A value that is either one
Tor a list of them, serialized without the list when single. - Verification
Error - Why a JWS signature did not verify.
Traits§
- JwsVerifier
- Verifies JWS signatures.
- Signer
- Produces JWS signatures.
Functions§
- ecdsa_
signature_ from_ der - A DER
ECDSA-Sig-Value(RFC 3279 §2.2.3) as the JWS signature foralg(RFC 7518 §3.4):r || s, each left-padded to the curve’s size, withsnormalized to the lower half of the group order for ES256K. - encode_
compact - Encodes
payloadunderheaderas a compact JWS signed bysigner. - normalize_
ecdsa_ signature - A raw
r || ssignature foralg, withsnormalized to the lower half of the group order for ES256K. ES256 and ES384 signatures are returned unchanged once their length is checked:DefaultVerifieraccepts eithersfor ES256.