jwks

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRSAPublicKeyNotFound is returned when a certificate does not contain an RSA public key.
	ErrRSAPublicKeyNotFound = errors.New("not a RSA public key")
	// ErrCertificateNotFound is returned when no certificate is provided.
	ErrCertificateNotFound = errors.New("certificate not found")
	// ErrDuplicateKID is returned when duplicate key IDs are detected.
	ErrDuplicateKID = errors.New("duplicate kid")
	// ErrKeyTypeUnsupported is returned when an unsupported key type is encountered.
	ErrKeyTypeUnsupported = errors.New("key type unsupported")
	// ErrInvalidKey is returned when key validation fails.
	ErrInvalidKey = errors.New("invalid key")
)

Functions

This section is empty.

Types

type Input

type Input struct {
	Kty       KeyType
	Alg       string
	Use       string
	KeyOps    []string
	Kid       string
	X509Certs []x509.Certificate
}

Input is used to build JWKS from a set of keys and certificates.

type JWKS

type JWKS struct {
	Keys []Key `json:"keys"`
}

JWKS represents a JSON Web Key Set, containing multiple JWK keys.

func New

func New(inputs ...Input) (*JWKS, error)

New constructs a JWKS from one or more KeyInput values. It ensures each key has a unique KID and at least one certificate.

func (*JWKS) Decode

func (j *JWKS) Decode(r io.Reader) error

Decode reads JSON data from the provided io.Reader and populates the JWKS struct. It returns an error if decoding fails or if no keys are found in the JWKS. If the JWKS contains no keys, ErrCertificateNotFound is returned.

func (*JWKS) Encode

func (j *JWKS) Encode(w io.Writer) error

Encode writes the JWKS (JSON Web Key Set) to the provided io.Writer in JSON format. Returns an error if encoding fails.

type Key

type Key struct {
	Kty    KeyType  `json:"kty"`     // Key type (e.g., "RSA")
	Alg    string   `json:"alg"`     // Algorithm intended for use with the key
	Use    string   `json:"use"`     // Intended use of the public key
	KeyOps []string `json:"key_ops"` // Permitted operations for the key
	Kid    string   `json:"kid"`     // Key ID
	X5c    []string `json:"x5c"`     // X.509 certificate chain
	N      string   `json:"n"`       // RSA modulus
	E      string   `json:"e"`       // RSA public exponent
}

Key defines the structure of a single JSON Web Key.

func (Key) Validate

func (k Key) Validate() error

type KeyType

type KeyType string

KeyType specifies the type of cryptographic key (e.g., "RSA").

var KeyTypeRSA KeyType = "RSA"

KeyTypeRSA is the constant for RSA key type.

Jump to

Keyboard shortcuts

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