Documentation ¶
Index ¶
- func Base64Bytesify(s string) []byte
- func ComputeHash(h crypto.Hash, data []byte) ([]byte, error)
- func GetRandomBytes(n uint16) []byte
- func GetRandomUint32() uint32
- func HexBytesify(h string) []byte
- func MarshalCBOR(v any) ([]byte, error)
- func MustMarshalCBOR(v any) []byte
- func RegisterEncryptor(kty int, alg Alg, fn EncryptorFactory)
- func RegisterMACer(kty int, alg Alg, fn MACerFactory)
- func RegisterSigner(kty int, alg Alg, crv Crv, fn SignerFactory)
- func RegisterVerifier(kty int, alg Alg, crv Crv, fn VerifierFactory)
- func ToInt(v any) (int, error)
- func UnmarshalCBOR(data []byte, v any) error
- func ValidCBOR(data []byte) error
- type Alg
- type ByteStr
- type Crv
- type Encryptor
- type EncryptorFactory
- type IntMap
- func (m IntMap) GetBool(k int) (bool, error)
- func (m IntMap) GetBytes(k int) (b []byte, err error)
- func (m IntMap) GetInt(k int) (int, error)
- func (m IntMap) GetInt64(k int) (int64, error)
- func (m IntMap) GetString(k int) (string, error)
- func (m IntMap) GetUint64(k int) (uint64, error)
- func (m IntMap) Has(k int) bool
- type Key
- func (k Key) Alg() Alg
- func (k Key) BaseIV() ByteStr
- func (k Key) Bytesify() []byte
- func (k Key) Encryptor() (Encryptor, error)
- func (k Key) GetBool(p int) (bool, error)
- func (k Key) GetBytes(p int) ([]byte, error)
- func (k Key) GetInt(p int) (int, error)
- func (k Key) GetInt64(p int) (int64, error)
- func (k Key) GetString(p int) (string, error)
- func (k Key) GetUint64(p int) (uint64, error)
- func (k Key) Has(p int) bool
- func (k Key) Kid() ByteStr
- func (k Key) Kty() int
- func (k Key) MACer() (MACer, error)
- func (k Key) MarshalCBOR() ([]byte, error)
- func (k Key) Ops() Ops
- func (k Key) SetKid(kid ByteStr)
- func (k Key) SetOps(os Ops)
- func (k Key) Signer() (Signer, error)
- func (k *Key) UnmarshalCBOR(data []byte) error
- func (k Key) Verifier() (Verifier, error)
- type KeySet
- type MACer
- type MACerFactory
- type Ops
- type Signer
- type SignerFactory
- type Signers
- type Verifier
- type VerifierFactory
- type Verifiers
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Base64Bytesify ¶
Base64Bytesify converts a base64url string to []byte. It returns nil if the string is not a valid base64url string.
func ComputeHash ¶
ComputeHash computes a hash of the given data using the given hash.
func GetRandomBytes ¶
GetRandomBytes randomly generates n bytes.
func GetRandomUint32 ¶
func GetRandomUint32() uint32
GetRandomUint32 randomly generates an unsigned 32-bit integer.
func HexBytesify ¶
HexBytesify converts a hex string to []byte. It returns nil if the string is not a valid hex string.
func MarshalCBOR ¶
MarshalCBOR marshals value with the special cbor.EncOptions.
func MustMarshalCBOR ¶
MustMarshalCBOR marshals value with the special cbor.EncOptions. It will panic if marshaling failed.
func RegisterEncryptor ¶
func RegisterEncryptor(kty int, alg Alg, fn EncryptorFactory)
RegisterEncryptor registers a EncryptorFactory for the given key type, algorithm.
func RegisterMACer ¶
func RegisterMACer(kty int, alg Alg, fn MACerFactory)
RegisterMACer registers a MACerFactory for the given key type, algorithm.
func RegisterSigner ¶
func RegisterSigner(kty int, alg Alg, crv Crv, fn SignerFactory)
RegisterSigner registers a SignerFactory for the given key type, algorithm, and curve. For example, to register a SignerFactory for ed25519 signer:
key.RegisterSigner(iana.KeyTypeOKP, iana.AlgorithmEdDSA, iana.EllipticCurveEd25519, ed25519.NewSigner)
func RegisterVerifier ¶
func RegisterVerifier(kty int, alg Alg, crv Crv, fn VerifierFactory)
RegisterVerifier registers a VerifierFactory for the given key type, algorithm, and curve.
func ToInt ¶ added in v0.6.0
ToInt converts the given value to int, the range is [math.MinInt32, math.MaxInt32].
func UnmarshalCBOR ¶
UnmarshalCBOR unmarshals data into value with the special cbor.DecOptions.
Types ¶
type Alg ¶
type Alg int
Algorithm represents an IANA algorithm entry in the COSE Algorithms registry.
Reference https://www.iana.org/assignments/cose/cose.xhtml#algorithms
type ByteStr ¶
type ByteStr []byte
ByteStr represents a byte string.
func (ByteStr) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for ByteStr.
func (ByteStr) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for ByteStr.
type Encryptor ¶
type Encryptor interface { // Encrypt encrypts a plaintext with the given nonce and additional data. // It returns the ciphertext or error. Encrypt(nonce, plaintext, additionalData []byte) (ciphertext []byte, err error) // Decrypt decrypts a ciphertext with the given nonce and additional data. // It returns the corresponding plaintext or error. Decrypt(nonce, ciphertext, additionalData []byte) (plaintext []byte, err error) // NonceSize returns the size of the nonce for encrypting and decrypting. NonceSize() int // Key returns the symmetric key in Encryptor. // If the "key_ops" field is present, it MUST include "encrypt" 3 when encrypting an plaintext. // If the "key_ops" field is present, it MUST include "decrypt" 4 when decrypting an ciphertext. Key() Key }
Encryptor is the encrypting and decrypting interface for content encryption. It is used in COSE_Encrypt and COSE_Encrypt0.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-8.3
type EncryptorFactory ¶
EncryptorFactory is a function that returns a Encryptor for the given key.
type IntMap ¶
IntMap represents a map of IntKey to any value. It is base type of key.Key, cose.Header, cwt.ClaimsMap.
func (IntMap) GetBool ¶
GetBool returns the value for the key as an boolean. If the key is not present, it returns (false, nil). If the underlying value's Kind is not Bool, it returns (false, error).
func (IntMap) GetBytes ¶
GetBytes returns the value for the key as an []byte. If the key is not present, it returns (nil, nil). If the underlying value is not a slice of bytes or an addressable array of bytes, it returns (nil, error).
func (IntMap) GetInt ¶
GetInt returns the value for the key as an int. If the key is not present, it returns (0, nil). If the underlying value's Kind is not Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Int64, or the value's range is out of [math.MinInt32, math.MaxInt32], it returns (0, error).
func (IntMap) GetInt64 ¶ added in v0.6.0
GetInt64 returns the value for the key as an int64. If the key is not present, it returns (0, nil). If the underlying value's Kind is not Int, Int8, Int16, Int32, Int64, Uint, Uint8, Uint16, Uint32, Int64, or the value is overflows, it returns (0, error).
func (IntMap) GetString ¶
GetString returns the value for the key as an string. If the key is not present, it returns ("", nil). If the underlying value is not a string, it returns ("", error).
type Key ¶
type Key IntMap
Key represents a COSE_Key object.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-7
func (Key) Alg ¶
Alg returns the key algorithm. If It is elliptic-curves key and algorithm is not present, it will return the algorithm that matched the curve. Reference https://www.iana.org/assignments/cose/cose.xhtml#algorithms
func (Key) BaseIV ¶
BaseIV returns the base IV to be XORed with Partial IVs.
Reference https://www.iana.org/assignments/cose/cose.xhtml#key-common-parameters
func (Key) Bytesify ¶
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (Key) Encryptor ¶
Encryptor returns a Encryptor for the given key. If the key is nil, or EncryptorFactory for the given key type, algorithm not registered, an error is returned.
func (Key) GetBytes ¶
GetBytes returns the value of the given parameter as a slice of bytes, or a error.
func (Key) GetInt ¶ added in v0.6.0
GetInt returns the value of the given parameter as a int, or a error.
func (Key) GetInt64 ¶ added in v0.6.0
GetInt64 returns the value of the given parameter as a int64, or a error.
func (Key) GetString ¶ added in v0.6.0
GetString returns the value of the given parameter as a string, or a error.
func (Key) GetUint64 ¶ added in v0.6.0
GetUint64 returns the value of the given parameter as a uint64, or a error.
func (Key) Kid ¶
Kid returns the key identifier. If the key identifier is not present, or the underlying value's Kind is not []byte, it returns nil.
func (Key) Kty ¶
Kty returns the key type. If the key is nil, it returns KtyReserved.
Reference https://www.iana.org/assignments/cose/cose.xhtml#key-type
func (Key) MACer ¶
MACer returns a MACer for the given key. If the key is nil, or MACerFactory for the given key type, algorithm not registered, an error is returned.
func (Key) MarshalCBOR ¶
MarshalCBOR implements the CBOR Marshaler interface for Key.
func (Key) Ops ¶
Ops returns the key operations, or nil.
Reference https://www.iana.org/assignments/cose/cose.xhtml#key-common-parameters
func (Key) Signer ¶
Signer returns a Signer for the given key. If the key is nil, or SignerFactory for the given key type, algorithm, and curve not registered, an error is returned.
func (*Key) UnmarshalCBOR ¶ added in v0.6.0
UnmarshalCBOR implements the CBOR Unmarshaler interface for Key.
type KeySet ¶
type KeySet []Key
func (KeySet) Lookup ¶
Lookup returns the first key matching the given key id. return nil if there are no keys matching the key id
type MACer ¶
type MACer interface { // MACCreate computes message authentication code (MAC) for the given data. MACCreate(data []byte) ([]byte, error) // MACVerify verifies whether the given MAC is a correct message authentication code (MAC) the given data. MACVerify(data, mac []byte) error // Key returns the key in MACer. // If the "key_ops" field is present, it MUST include "MAC create" 9 when creating an HMAC authentication tag. // If the "key_ops" field is present, it MUST include "MAC verify" 10 when verifying an HMAC authentication tag. Key() Key }
MACer is the MAC interface for MAC objects. It is used in COSE_Mac and COSE_Mac0.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-8.2
type MACerFactory ¶
MACerFactory is a function that returns a MACer for the given key.
type Ops ¶
type Ops []int
Ops represents the key operations.
func (Ops) EmptyOrHas ¶
EmptyOrHas returns true if the list of operations is empty, or the given operation is in the list of operations.
type Signer ¶
type Signer interface { // Computes the digital signature for data. Sign(data []byte) ([]byte, error) // Key returns the private key in Signer. // If the "key_ops" field is present, it MUST include "sign" 1. Key() Key }
Signer is the signing interface for signing objects. It is used in COSE_Sign and COSE_Sign1.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-8.1
type SignerFactory ¶
SignerFactory is a function that returns a Signer for the given key.
type Signers ¶
type Signers []Signer
Signers is a list of signers to be used for signing with one or more signers.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-4-1
type Verifier ¶
type Verifier interface { // Verifies returns nil if signature is a valid signature for data; otherwise returns an error. Verify(data, signature []byte) error // Key returns the public key in Verifier. // The key returned by this method should not include private key bytes. // If the "key_ops" field is present, it MUST include "verify" 12. Key() Key }
Verifier is the verifying interface for signing objects.
Reference https://datatracker.ietf.org/doc/html/rfc9052#section-8.1
type VerifierFactory ¶
VerifierFactory is a function that returns a Verifier for the given key.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in https://datatracker.ietf.org/doc/html/rfc9053#name-key-derivation-functions-kd.
|
Package hkdf implements the HMAC-based Extract-and-Expand Key Derivation Function (HKDF) as defined in https://datatracker.ietf.org/doc/html/rfc9053#name-key-derivation-functions-kd. |