Documentation ¶
Overview ¶
Package jwk implements JSON Web Key (JWK) specification.
Index ¶
- Constants
- func DefaultKeyIDGenerator() (string, error)
- func SetIDGenerator(f KeyIDGenerator)
- type ErrGenID
- type ErrIncompatibleAlg
- type ErrUnknownType
- type ErrUnsupportedEC
- type Key
- func (k *Key) GenerateID() error
- func (k *Key) IsECDSA() bool
- func (k *Key) IsRSA() bool
- func (k *Key) IsSymmetric() bool
- func (k *Key) Key() (interface{}, error)
- func (mj *Key) MarshalJSON() ([]byte, error)
- func (mj *Key) MarshalJSONBuf(buf fflib.EncodingBuffer) error
- func (k *Key) RemovePrivateFields()
- func (k *Key) SetKey(key interface{}, alg string) error
- func (uj *Key) UnmarshalJSON(input []byte) error
- func (uj *Key) UnmarshalJSONFFLexer(fs *fflib.FFLexer, state fflib.FFParseState) error
- type KeyIDGenerator
- type Set
Constants ¶
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 ¶
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.
type ErrIncompatibleAlg ¶
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 ¶
GenerateKey generates a key of the given algorithm, bit size and life duration
func (*Key) GenerateID ¶
GenerateID creates a new identifier for current key.
func (*Key) IsSymmetric ¶
IsSymmetric returns whether current key type is symmetric.
func (*Key) MarshalJSON ¶
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) UnmarshalJSON ¶
func (*Key) UnmarshalJSONFFLexer ¶
type KeyIDGenerator ¶
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 (*Set) MarshalJSONBuf ¶
func (mj *Set) MarshalJSONBuf(buf fflib.EncodingBuffer) error