jwk

package
v1.0.0-dev.18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package jwk parses a JWK Set (RFC 7517) into the public keys oidc verifies ID tokens with: RSA, EC on P-256, P-384 and P-521, and OKP Ed25519 (RFC 7518 §6, RFC 8037 §2).

Index

Constants

View Source
const MaxKeys = 100

MaxKeys is the most keys a JWK Set may hold before Parse refuses it.

Variables

View Source
var ErrSet = errors.New("jwk: JWK Set refused")

ErrSet is the error Parse wraps when it refuses a whole JWK Set.

Functions

This section is empty.

Types

type Alg

type Alg uint8

Alg is one row of the accepted-algorithm table; the zero Alg names no row.

const (
	RS256 Alg = iota + 1
	RS384
	RS512
	PS256
	PS384
	PS512
	ES256
	ES384
	ES512
	EdDSA
)

The rows, one per JWS alg value (RFC 7518 §3.1), except EdDSA, which the fully specified name Ed25519 also names (RFC 9864 §2.2).

func ParseAlg

func ParseAlg(name string) (Alg, bool)

ParseAlg returns the row a JWS alg header value names, case-sensitively.

func (Alg) Hash

func (a Alg) Hash() crypto.Hash

Hash is the row's digest; zero for EdDSA, which hashes internally.

func (Alg) Scheme

func (a Alg) Scheme() Scheme

Scheme is the row's signature scheme.

func (Alg) SignatureSize

func (a Alg) SignatureSize() int

SignatureSize is the exact signature length an ES row splits into R ‖ S (RFC 7518 §3.4); zero for the rows whose verify call checks the size itself.

func (Alg) String

func (a Alg) String() string

String is the row's registered name; EdDSA's is "EdDSA".

type Key

type Key struct {
	// contains filtered or unexported fields
}

Key is one usable verification key.

func (Key) Fits

func (k Key) Fits(a Alg) bool

Fits reports whether the key may verify under row a: its type and curve are a's, and its own alg, when present, names a (RFC 8725 §3.1).

func (Key) KeyID

func (k Key) KeyID() (string, bool)

KeyID is the key's kid, and whether it has one.

func (Key) Public

func (k Key) Public() crypto.PublicKey

Public is the key: *rsa.PublicKey, *ecdsa.PublicKey or ed25519.PublicKey.

type Scheme

type Scheme uint8

Scheme is the signature scheme a row verifies with.

const (
	PKCS1v15 Scheme = iota + 1
	PSS
	ECDSA
	Ed25519
)

The schemes of RFC 7518 §3.3, §3.5, §3.4 and RFC 8037 §3.1.

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set is the usable keys of a JWK Set, in the set's order.

func Parse

func Parse(data []byte) (Set, error)

Parse classifies every JWK of a JWK Set. It refuses the whole set, with ErrSet, when the document is not one, holds more than MaxKeys keys or an entry that is not an object, or publishes a private RSA, EC or OKP key; it skips any other key it cannot use (RFC 7517 §5), so the Set may be empty.

func (Set) All

func (s Set) All() iter.Seq[Key]

All yields the usable keys in the set's order.

func (Set) Len

func (s Set) Len() int

Len is the number of usable keys.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL