jwk

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: 12 Imported by: 3

Documentation

Overview

Package jwk implements JSON Web Key (JWK) specification.

Index

Constants

View Source
const (
	// KeyTypeECDSA defines the type code for ECDSA keys.
	KeyTypeECDSA = "EC"

	// KeyTypeRSA defines the type code for RSA keys.
	KeyTypeRSA = "RSA"

	// KeyTypeSymmetric defines the type code for symmetric keys.
	KeyTypeSymmetric = "oct"
)

Variables

This section is empty.

Functions

func DefaultKeyIDGenerator

func DefaultKeyIDGenerator() (string, error)

DefaultKeyIDGenerator defines the default implementation for generating key identifiers.

func SetIDGenerator

func SetIDGenerator(f KeyIDGenerator)

SetIDGenerator defines a custom generator for key identifiers.

Types

type ErrGenID

type ErrGenID string

An ErrGenID represents an error when could not generate a new identifier for a JWK key.

func (ErrGenID) Error

func (e ErrGenID) Error() string

Error returns string representation of current instance error.

type ErrIncompatibleAlg

type ErrIncompatibleAlg struct {
	Type      string
	Algorithm string
}

An ErrIncompatibleAlg represents an error when key type and algorithm are not compatible with each other.

func (ErrIncompatibleAlg) Error

func (e ErrIncompatibleAlg) Error() string

Error returns string representation of current instance error.

type ErrUnknownType

type ErrUnknownType string

An ErrUnknownType represents an error when the type specified for JWK key is not supported by current implementation.

func (ErrUnknownType) Error

func (e ErrUnknownType) Error() string

Error returns string representation of current instance error.

type ErrUnsupportedEC

type ErrUnsupportedEC string

An ErrUnsupportedEC represents an error when specified curve for ECDSA key is not supported by current implementation.

func (ErrUnsupportedEC) Error

func (e ErrUnsupportedEC) Error() string

Error returns string representation of current instance error.

type Key

type Key struct {
	ID        string    `bson:"_id" json:"kid"`
	Type      string    `bson:"kty" json:"kty"`
	Algorithm string    `bson:"alg" json:"alg"`
	Usage     string    `bson:"use" json:"use"`
	NotBefore time.Time `bson:"nbf,omitempty" json:"-"`
	ExpireAt  time.Time `bson:"exp,omitempty" json:"-"`

	Curve string `bson:"crv,omitempty" json:"crv,omitempty"`
	X     string `bson:"x,omitempty" json:"x,omitempty"`
	Y     string `bson:"y,omitempty" json:"y,omitempty"`
	D     string `bson:"d,omitempty" json:"d,omitempty"`

	N       string `bson:"n,omitempty" json:"n,omitempty"`
	E       string `bson:"e,omitempty" json:"e,omitempty"`
	PrimeP  string `bson:"p,omitempty" json:"p,omitempty"`
	PrimeQ  string `bson:"q,omitempty" json:"q,omitempty"`
	PreDp   string `bson:"dp,omitempty" json:"dp,omitempty"`
	PreDq   string `bson:"dq,omitempty" json:"dq,omitempty"`
	PreQinv string `bson:"qi,omitempty" json:"qi,omitempty"`

	K string `bson:"k,omitempty" json:"k,omitempty"`
}

A Key represents a key as defined by JWK specification.

func GenerateKey

func GenerateKey(alg string, bits, days int) (*Key, error)

GenerateKey generates a key of the given algorithm, bit size and life duration

func (*Key) GenerateID

func (k *Key) GenerateID() error

GenerateID creates a new identifier for current key.

func (*Key) IsECDSA

func (k *Key) IsECDSA() bool

IsECDSA returns whether current key type is ECDSA.

func (*Key) IsRSA

func (k *Key) IsRSA() bool

IsRSA returns whether current key type is RSA.

func (*Key) IsSymmetric

func (k *Key) IsSymmetric() bool

IsSymmetric returns whether current key type is symmetric.

func (*Key) Key

func (k *Key) Key() (interface{}, error)

Key creates a raw key instance based on current key specification.

func (*Key) MarshalJSON

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

func (*Key) MarshalJSONBuf

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

func (*Key) RemovePrivateFields

func (k *Key) RemovePrivateFields()

RemovePrivateFields discards all private information of current key.

func (*Key) SetKey

func (k *Key) SetKey(key interface{}, alg string) error

SetKey parses specified raw key and sets current key to match it.

func (*Key) UnmarshalJSON

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

func (*Key) UnmarshalJSONFFLexer

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

type KeyIDGenerator

type KeyIDGenerator func() (string, error)

The KeyIDGenerator type is an adapter to allow to set custom identifiers generator for keys.

type Set

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

A Set represents a set of keys as defined by JWK specification.

func (*Set) MarshalJSON

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

func (*Set) MarshalJSONBuf

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

func (*Set) UnmarshalJSON

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

func (*Set) UnmarshalJSONFFLexer

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

Directories

Path Synopsis
Package adapters implements adapters for JWK data.
Package adapters implements adapters for JWK data.
Package services implements services which provides JWK set.
Package services implements services which provides JWK set.

Jump to

Keyboard shortcuts

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