jwt

package
v0.0.0-...-c1ce609 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMalformedToken     = errors.New("malformed packet")
	ErrMalformedHeader    = errors.New("malformed header")
	ErrInvalidSignature   = errors.New("signature is invalid")
	ErrNoVerifiersWithKID = errors.New("no verifiers with kid")
)
View Source
var (
	// ErrInvalidHeaderType is returned when the type of the header is wrong
	ErrInvalidHeaderType = errors.New("invalid header type")
)

Functions

func Marshal

func Marshal(rand io.Reader, payload interface{}, signer Signer) ([]byte, error)

func MarshalWithHeader

func MarshalWithHeader(rand io.Reader, payload interface{}, header Header, signer Signer) ([]byte, error)

func RegisterAlgorithm

func RegisterAlgorithm(a Algorithm, alg jwa.Algoritm)

func RegisterKeyType

func RegisterKeyType(k KeyType, p KeyParser)

func Unmarshal

func Unmarshal(b []byte, payload interface{}, verifiers Verifiers) (string, error)

func UnmarshalPayload

func UnmarshalPayload(b []byte, payload interface{}) error

func UnmarshalWithHeader

func UnmarshalWithHeader(b []byte, payload interface{}, header Header, verifiers Verifiers) (string, error)

Types

type Algorithm

type Algorithm uint8

Algorithm is the different JWT algoritms

const (
	// None is a token without a signature
	None Algorithm = 1 + iota
	// ES256 ECDSA P-256 and SHA-256
	ES256
	// ES384 ECDSA P-384 with SHA-384
	ES384
	// ES512 ECDSA P-521 with SHA-512
	ES512
	RS256
	RS384
	RS512
)

func GetAlgorithm

func GetAlgorithm(s string) Algorithm

func (Algorithm) NewSigner

func (a Algorithm) NewSigner(kid string, key crypto.PrivateKey) signer

func (Algorithm) NewVerifier

func (a Algorithm) NewVerifier(kid string, key crypto.PublicKey) verifier

func (Algorithm) SignatureSize

func (a Algorithm) SignatureSize() int

func (Algorithm) String

func (a Algorithm) String() string
type Header interface {
	Valid() error
	Alg() Algorithm
	Kid() string
	SetAlg(a Algorithm)
	SetKid(s string)
}

Header is the interface for minimum header

type KeyParser

type KeyParser interface {
	ParseSigner(kid string, b []byte) (Signer, error)
	ParseVerifier(kid string, b []byte) (Verifier, error)
}

type KeyType

type KeyType uint8
const (
	// Elliptic Curve
	EC KeyType = 1 + iota
	// RSA
	RSA
	// Octet Sequence
	OCT
)

func GetKeyType

func GetKeyType(s string) KeyType

func (KeyType) ParseSigner

func (k KeyType) ParseSigner(kid string, b []byte) (Signer, error)

func (KeyType) ParseVerifier

func (k KeyType) ParseVerifier(kid string, b []byte) (Verifier, error)

type Signer

type Signer interface {
	Sign(rand io.Reader, unsigned []byte) (signature []byte, err error)
	Algorithm() Algorithm
	KeyID() string
}

type Verifier

type Verifier interface {
	Verify(a Algorithm, kidSuggest string, signed, signature []byte) (kidUsed string, err error)
	Algorithm() Algorithm
	KeyID() string
}

type Verifiers

type Verifiers interface {
	Verify(a Algorithm, kidSuggest string, signed, signature []byte) (kidUsed string, err error)
}

func NewVerifiers

func NewVerifiers(keyIDMustMatch bool, vs ...Verifier) Verifiers

Jump to

Keyboard shortcuts

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