jwk

package
v0.0.0-...-391e729 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClaimKty = "kty"
	ClaimAlg = "alg"
	ClaimUse = "use"
	ClaimKid = "kid"
)

Variables

View Source
var (
	ErrMalformedKey = errors.New("malformed key")

	ErrUnknownType   = errors.New("unknown key type")
	ErrUnknownUse    = errors.New("unknown key usage")
	ErrMalformedJSON = errors.New("malformed JSON")
)

Functions

This section is empty.

Types

type Header struct {
	Kty KeyType
	Alg jwa.KeyAlgorithm `json:"alg,omitempty`
	Kid string           `json:"kid,omitempty`
	Use KeyUsage         `json:"use,omitempty`
}

Header represents the JWK claims shared by every key type

func (Header) Algorithm

func (h Header) Algorithm() jwa.KeyAlgorithm

func (Header) ID

func (h Header) ID() string

func (Header) Type

func (h Header) Type() KeyType

func (Header) Usage

func (h Header) Usage() KeyUsage

type Key

type Key interface {
	// Type returns the type of the key (`kty` claim)
	Type() KeyType
	// Alg returns the algorithm of the key (`alg“ claim)
	Algorithm() jwa.KeyAlgorithm
	// ID returns the unique identifier of the key (`kid` claim)
	ID() string
	// Usage returns the usage of the key (`use` claim)
	Usage() KeyUsage
	// Thumbprint returns the JWK thumbprint of the key.
	Thumbprint(hash crypto.Hash) ([]byte, error)
}

func Parse

func Parse(key []byte) (Key, error)

func ParseReader

func ParseReader(r io.Reader) (Key, error)

func ParseString

func ParseString(key string) (Key, error)

type KeyType

type KeyType string
const (
	EC  KeyType = "EC"
	RSA KeyType = "RSA"
	OKP KeyType = "OKP"
)

type KeyUsage

type KeyUsage string

KeyUsage denotes what the key is supposed to be used for.

const (
	Unspecified KeyUsage = ""
	Signing     KeyUsage = "sig"
	Encryption  KeyUsage = "enc"
)

type RSAPrivateKey

type RSAPrivateKey struct {
	Header
	// contains filtered or unexported fields
}

func (RSAPrivateKey) Thumbprint

func (k RSAPrivateKey) Thumbprint(hash crypto.Hash) ([]byte, error)

type RSAPublicKey

type RSAPublicKey struct {
	Header
	// contains filtered or unexported fields
}

func (RSAPublicKey) Thumbprint

func (k RSAPublicKey) Thumbprint(hash crypto.Hash) ([]byte, error)

Jump to

Keyboard shortcuts

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