jws

package
v0.0.0-...-4fd71c7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package jws implements JSON Web Signature (JWS) specification.

Index

Constants

View Source
const (
	// JWTHeaderType defines the type name for JWT header.
	JWTHeaderType = "JOSE"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ErrGetKey

type ErrGetKey string

An ErrGetKey represents an error when was unable to retrieve token signing key.

func (ErrGetKey) Error

func (e ErrGetKey) Error() string

Error returns string representation of current instance error.

type ErrInvalidFormat

type ErrInvalidFormat string

An ErrInvalidFormat represents an error when token format is invalid.

func (ErrInvalidFormat) Error

func (e ErrInvalidFormat) Error() string

Error returns string representation of current instance error.

type ErrInvalidSignature

type ErrInvalidSignature string

An ErrInvalidSignature represents an error when token signature could not be validated.

func (ErrInvalidSignature) Error

func (e ErrInvalidSignature) Error() string

Error returns string representation of current instance error.

type ErrInvalidToken

type ErrInvalidToken string

An ErrInvalidToken represents an error when a token is not valid by time being.

func (ErrInvalidToken) Error

func (e ErrInvalidToken) Error() string

Error returns string representation of current instance error.

type GetKeyFunc

type GetKeyFunc func(Header) (interface{}, error)

GetKeyFunc defines a function to retrieve a key for specified token.

type Header interface {
	GetID() string
	GetAlgorithm() string
	GetJWKSetURL() string

	json.Marshaler
	json.Unmarshaler
}

A Header represents the JOSE Header which describes the digital signature or MAC applied to the JWS Protected Header and the JWS Payload and optionally additional properties of the JWS.

type RegHeader

type RegHeader struct {
	ID          string   `json:"kid,omitempty"`
	Type        string   `json:"typ,omitempty"`
	ContentType string   `json:"cty,omitempty"`
	Algorithm   string   `json:"alg"`
	JWKSetURL   string   `json:"jku,omitempty"`
	JWK         string   `json:"jwk,omitempty"`
	X509URL     string   `json:"x5u,omitempty"`
	X509Chain   string   `json:"x5c,omitempty"`
	X509SHA1    string   `json:"x5t,omitempty"`
	X509SHA256  string   `json:"x5t#S256,omitempty"`
	Critical    []string `json:"crit,omitempty"`
}

A RegHeader represents the JOSE header with all registered parameter names.

func NewHeader

func NewHeader(alg string) *RegHeader

NewHeader creates a new instance of Header type.

func (*RegHeader) GetAlgorithm

func (h *RegHeader) GetAlgorithm() string

GetAlgorithm returns the algorithm used to sign current token.

func (*RegHeader) GetID

func (h *RegHeader) GetID() string

GetID returns the identifier of the key used to sign current token.

func (*RegHeader) GetJWKSetURL

func (h *RegHeader) GetJWKSetURL() string

GetJWKSetURL returns a URL to retrieve the key used to sign current token.

func (*RegHeader) MarshalJSON

func (mj *RegHeader) MarshalJSON() ([]byte, error)

func (*RegHeader) MarshalJSONBuf

func (mj *RegHeader) MarshalJSONBuf(buf fflib.EncodingBuffer) error

func (*RegHeader) UnmarshalJSON

func (uj *RegHeader) UnmarshalJSON(input []byte) error

func (*RegHeader) UnmarshalJSONFFLexer

func (uj *RegHeader) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error

type SignedToken

type SignedToken struct {
	Header  Header
	Payload jwt.Claims
}

A SignedToken represents a token encapsuled by JWS.

func DecodeAndValidate

func DecodeAndValidate(
	token string,
	header Header,
	payload jwt.Claims,
	getKey GetKeyFunc,
) (*SignedToken, error)

DecodeAndValidate decodes an existing token and validates it.

func NewSignedToken

func NewSignedToken(alg string) *SignedToken

NewSignedToken creates a new instance of SignedToken using default header and payload.

func (*SignedToken) EncodeAndSign

func (t *SignedToken) EncodeAndSign(key interface{}) (string, error)

EncodeAndSign creates a string representation of current token and appends a signature.

func (*SignedToken) Validate

func (t *SignedToken) Validate() bool

Validate returns whether current token header and payload is valid.

Directories

Path Synopsis
Package services implements services which provides JWK signing and verifying.
Package services implements services which provides JWK signing and verifying.

Jump to

Keyboard shortcuts

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