Documentation ¶
Index ¶
Constants ¶
const ( // AlgHS256 is the HMAC using SHA-256 algorithm. AlgHS256 ALG = "HS256" // AlgHS384 is the HMAC using SHA-384 algorithm. AlgHS384 ALG = "HS384" // AlgHS512 is the HMAC using SHA-512 algorithm. AlgHS512 ALG = "HS512" // AlgRS256 is the RSASSA-PKCS1-v1_5 using SHA-256 algorithm. AlgRS256 ALG = "RS256" // AlgRS384 is the RSASSA-PKCS1-v1_5 using SHA-384 algorithm. AlgRS384 ALG = "RS384" // AlgRS512 is the RSASSA-PKCS1-v1_5 using SHA-512 algorithm. AlgRS512 ALG = "RS512" // AlgES256 is the ECDSA using P-256 and SHA-256 algorithm. AlgES256 ALG = "ES256" // AlgES384 is the ECDSA using P-384 and SHA-384 algorithm. AlgES384 ALG = "ES384" // AlgES512 is the ECDSA using P-521 and SHA-512 algorithm. AlgES512 ALG = "ES512" // AlgPS256 is the RSASSA-PSS using SHA-256 and MGF1 with SHA-256 algorithm. AlgPS256 ALG = "PS256" // AlgPS384 is the RSASSA-PSS using SHA-384 and MGF1 with SHA-384 algorithm. AlgPS384 ALG = "PS384" // AlgPS512 is the RSASSA-PSS using SHA-512 and MGF1 with SHA-512 algorithm. AlgPS512 ALG = "PS512" // AlgNone is the No digital signature or MAC performed algorithm. AlgNone ALG = "none" // ALGEdDSA is the EdDSA algorithm. ALGEdDSA ALG = "EdDSA" // KeyTypeEC is the key type for ECDSA. KeyTypeEC KTY = "EC" // KeyTypeOKP is the key type for EdDSA. KeyTypeOKP KTY = "OKP" // KeyTypeRSA is the key type for RSA. KeyTypeRSA KTY = "RSA" // KeyTypeOct is the key type for octet sequences, such as HMAC. KeyTypeOct KTY = "oct" // CurveEd25519 is a curve for EdDSA. CurveEd25519 CRV = "Ed25519" // CurveP256 is a curve for ECDSA. CurveP256 CRV = "P-256" // CurveP384 is a curve for ECDSA. CurveP384 CRV = "P-384" // CurveP521 is a curve for ECDSA. CurveP521 CRV = "P-521" )
Variables ¶
var ( // ErrKeyUnmarshalParameter indicates that a JWK's attributes are invalid and cannot be unmarshaled. ErrKeyUnmarshalParameter = errors.New("unable to unmarshal JWK due to invalid attributes") // ErrUnsupportedKeyType indicates a key type is not supported. ErrUnsupportedKeyType = errors.New("unsupported key type") )
var ErrKeyNotFound = errors.New("key not found")
ErrKeyNotFound is returned by a Storage implementation when a key is not found.
Functions ¶
This section is empty.
Types ¶
type ALG ¶ added in v0.1.0
type ALG string
ALG is a set of "JSON Web Signature and Encryption Algorithms" types from https://www.iana.org/assignments/jose/jose.xhtml(JWA) as defined in https://www.rfc-editor.org/rfc/rfc7518#section-7.1
type CRV ¶ added in v0.1.0
type CRV string
CRV is a set of "JSON Web Key Elliptic Curve" types from https://www.iana.org/assignments/jose/jose.xhtml as mentioned in https://www.rfc-editor.org/rfc/rfc7518.html#section-6.2.1.1.
type JWKMarshal ¶ added in v0.1.0
type JWKMarshal struct { // TODO Check that ALG field is utilized fully. ALG ALG `json:"alg,omitempty"` // https://www.rfc-editor.org/rfc/rfc7517#section-4.4 and https://www.rfc-editor.org/rfc/rfc7518#section-4.1 CRV CRV `json:"crv,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.2.1.1 and https://www.rfc-editor.org/rfc/rfc8037.html#section-2 D string `json:"d,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.1 and https://www.rfc-editor.org/rfc/rfc7518#section-6.2.2.1 and https://www.rfc-editor.org/rfc/rfc8037.html#section-2 DP string `json:"dp,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.4 DQ string `json:"dq,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.5 E string `json:"e,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.1.2 K string `json:"k,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.4.1 // TODO Use KEYOPS field. // KEYOPTS []string `json:"key_ops,omitempty"` // https://www.rfc-editor.org/rfc/rfc7517#section-4.3 KID string `json:"kid,omitempty"` // https://www.rfc-editor.org/rfc/rfc7517#section-4.5 KTY KTY `json:"kty,omitempty"` // https://www.rfc-editor.org/rfc/rfc7517#section-4.1 N string `json:"n,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.1.1 OTH []OtherPrimes `json:"oth,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7 P string `json:"p,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.2 Q string `json:"q,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.3 QI string `json:"qi,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.6 // TODO Use USE field. // USE USE `json:"use,omitempty"` // https://www.rfc-editor.org/rfc/rfc7517#section-4.2 X string `json:"x,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.2.1.2 and https://www.rfc-editor.org/rfc/rfc8037.html#section-2 // TODO X.509 related fields. Y string `json:"y,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.2.1.3 }
JWKMarshal is used to marshal or unmarshal a JSON Web Key. https://www.rfc-editor.org/rfc/rfc7517 https://www.rfc-editor.org/rfc/rfc7518 https://www.rfc-editor.org/rfc/rfc8037
func KeyMarshal ¶ added in v0.1.0
func KeyMarshal[CustomKeyMeta any](meta KeyWithMeta[CustomKeyMeta], options KeyMarshalOptions) (JWKMarshal, error)
KeyMarshal transforms a KeyWithMeta into a JWKMarshal, which is used to marshal/unmarshal a JSON Web Key.
type JWKSMarshal ¶ added in v0.1.0
type JWKSMarshal struct {
Keys []JWKMarshal `json:"keys"`
}
JWKSMarshal is used to marshal or unmarshal a JSON Web Key Set.
type JWKSet ¶
JWKSet is a set of JSON Web Keys.
func (JWKSet[CustomKeyMeta]) JSONPrivate ¶ added in v0.1.0
JSONPrivate creates the JSON representation of the JWKSet public and private key material.
func (JWKSet[CustomKeyMeta]) JSONPublic ¶ added in v0.1.0
JSONPublic creates the JSON representation of the public keys in JWKSet.
func (JWKSet[CustomKeyMeta]) JSONWithOptions ¶ added in v0.1.0
func (j JWKSet[CustomKeyMeta]) JSONWithOptions(ctx context.Context, options KeyMarshalOptions) (json.RawMessage, error)
JSONWithOptions creates the JSON representation of the JWKSet with the given options.
type KTY ¶ added in v0.1.0
type KTY string
KTY is a set of "JSON Web Key Types" from https://www.iana.org/assignments/jose/jose.xhtml as mentioned in https://www.rfc-editor.org/rfc/rfc7517#section-4.1
type KeyMarshalOptions ¶ added in v0.1.0
KeyMarshalOptions are used to specify options for marshaling a JSON Web Key.
type KeyUnmarshalOptions ¶ added in v0.1.0
KeyUnmarshalOptions are used to specify options for unmarshaling a JSON Web Key.
type KeyWithMeta ¶
type KeyWithMeta[CustomKeyMeta any] struct { ALG ALG Custom CustomKeyMeta Key interface{} KeyID string }
KeyWithMeta is holds a Key and its metadata.
func KeyUnmarshal ¶ added in v0.1.0
func KeyUnmarshal[CustomKeyMeta any](jwk JWKMarshal, options KeyUnmarshalOptions) (KeyWithMeta[CustomKeyMeta], error)
KeyUnmarshal transforms a JWKMarshal into a KeyWithMeta, which contains the correct Go type for the cryptographic key.
func NewKey ¶
func NewKey[CustomKeyMeta any](key interface{}, keyID string) KeyWithMeta[CustomKeyMeta]
NewKey creates a new KeyWithMeta.
type OtherPrimes ¶ added in v0.1.0
type OtherPrimes struct { D string `json:"d,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7.2 R string `json:"r,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7.1 T string `json:"t,omitempty"` // https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7.3 }
OtherPrimes is for RSA private keys that have more than 2 primes. https://www.rfc-editor.org/rfc/rfc7518#section-6.3.2.7
type Storage ¶
type Storage[CustomKeyMeta any] interface { // DeleteKey deletes a key from the storage. It will return ok as true if the key was present for deletion. DeleteKey(ctx context.Context, keyID string) (ok bool, err error) // ReadKey reads a key from the storage. If the key is not present, it returns ErrKeyNotFound. Any pointers returned // should be considered read-only. ReadKey(ctx context.Context, keyID string) (KeyWithMeta[CustomKeyMeta], error) // SnapshotKeys reads a snapshot of all keys from storage. As with ReadKey, any pointers returned should be // considered read-only. SnapshotKeys(ctx context.Context) ([]KeyWithMeta[CustomKeyMeta], error) // WriteKey writes a key to the storage. If the key already exists, it will be overwritten. After writing a key, // any pointers written should be considered owned by the underlying storage. WriteKey(ctx context.Context, meta KeyWithMeta[CustomKeyMeta]) error }
Storage handles storage operations for a JWKSet.
func NewMemoryStorage ¶
NewMemoryStorage creates a new in-memory Storage implementation.