Documentation ¶
Index ¶
- Constants
- Variables
- type Algorithm
- type Config
- type Encoding
- func (e *Encoding) Decode(data []byte, config *Config) (Message, error)
- func (e *Encoding) DecodeWithExternal(data, external []byte, config *Config) (Message, error)
- func (e *Encoding) Encode(message Message) ([]byte, error)
- func (e *Encoding) EncodeWithExternal(message Message, external []byte) ([]byte, error)
- type ErrMinKeySize
- type ErrUnsupportedMessageTag
- type Headers
- func (h *Headers) Delete(key interface{})
- func (h *Headers) Get(key interface{}) (interface{}, error)
- func (h *Headers) GetProtected(key interface{}) (interface{}, error)
- func (h *Headers) Merge(other *Headers)
- func (h *Headers) Set(key, value interface{}) error
- func (h *Headers) SetProtected(key, value interface{}) error
- type Message
- type Sign1Message
- type SignMessage
- type Signer
- type Verifier
Constants ¶
const ( // MessageTagUnknown is the tag for unknown messages MessageTagUnkown = 0 // MessageTagEncrypt0 is the tag for encrypt messages without specifid recipients MessageTagEncrypt0 = 16 // MessageTagEncrypt is the tag for encrypt messages with specifid recipients MessageTagEncrypt = 96 // MessageTagSign1 is the tag for signed messages with single signer MessageTagSign1 = 18 // MessageTagSign is the tag for signed messages with multiple signers MessageTagSign = 98 // MessageTagMAC is the tag for MAC messages with specified recipients MessageTagMAC = 97 // MessageTagMAC0 is the tag for MAC messages where recipients are not specified MessageTagMAC0 = 17 )
const ( HeaderAlgorithm = "alg" HeaderCritical = "crit" HeaderContentType = "content type" HeaderKeyID = "kid" HeaderIV = "IV" HeaderPartialIV = "Partial IV" HeaderCounterSignature = "counter signature" )
Variables ¶
var ( // ErrUnsupportedKeyType represents an error when a key type is not supported. ErrUnsupportedKeyType = errors.New("unsupported key type") ErrUnavailableHashAlgorithm = errors.New("hash algorithm unavailable") // ErrUnsupportedAlgorithm represents an error when an algorithm is not supported. ErrUnsupportedAlgorithm = errors.New("unsupported algorithm") // ErrAlgorithmNotMatchKey represents an error when an algorithm does not match the key type. ErrAlgorithmNotMatchKey = errors.New("algorithm does not match key type") // ErrInvalidEllipticCurve represents an error when an elliptic curve size does not match the key. ErrInvalidEllipticCurve = errors.New("invalid elliptic curve") // ErrVerification represents a failure to verify a signature. ErrVerification = errors.New("verification error") )
var (
// StdEncoging is the COSE standard encoding
StdEncoding, _ = NewEncoding()
)
Functions ¶
This section is empty.
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm name
const ( // AlgorithmPS256 for signing with RSASSA-PSS w/ SHA-256 AlgorithmPS256 Algorithm = "PS256" // AlgorithmPS384 for signing with RSASSA-PSS w/ SHA-384 AlgorithmPS384 Algorithm = "PS384" // AlgorithmPS512 for signing with RSASSA-PSS w/ SHA-512 AlgorithmPS512 Algorithm = "PS512" // AlgorithmES512 for signing with ECDSA w/ SHA-512 AlgorithmES512 Algorithm = "ES512" // AlgorithmES384 for signing with ECDSA w/ SHA-384 AlgorithmES384 Algorithm = "ES384" // AlgorithmES256 for signing with ECDSA w/ SHA-256 AlgorithmES256 Algorithm = "ES256" // AlgorithmEdDSA for signing with EdDSA/Ed25519 AlgorithmEdDSA Algorithm = "EdDSA" )
type Config ¶
type Config struct { // GetVerifiers returns the verifiers for the given message signature GetVerifiers func(*Headers) ([]*Verifier, error) // Verified callback Verified func(*Verifier) }
Config is the configuration for the COSE encoding
type Encoding ¶
type Encoding struct {
// contains filtered or unexported fields
}
Encoding is the COSE encoding
func (*Encoding) DecodeWithExternal ¶
DecodeWithExternal decodes the given data with the given external data
type ErrMinKeySize ¶
type ErrMinKeySize struct {
Size int
}
ErrMinKeySize represents an error when a key is too small.
func (ErrMinKeySize) Error ¶
func (e ErrMinKeySize) Error() string
type ErrUnsupportedMessageTag ¶
type ErrUnsupportedMessageTag struct {
Tag uint64
}
ErrUnsupportedMessageTag represents an error when a message tag is not supported.
func (ErrUnsupportedMessageTag) Error ¶
func (e ErrUnsupportedMessageTag) Error() string
type Headers ¶
type Headers struct {
// contains filtered or unexported fields
}
Headers represents COSE protected and unprotected headers.
func MergeHeaders ¶
MergeHeaders merges the given headers into the new Headers instance.
func (*Headers) Delete ¶
func (h *Headers) Delete(key interface{})
Delete removes the header with the given key from protected and unprotected headers.
func (*Headers) Get ¶
Get returns the header with the given key from both protected and unprotected headers, prioritizing protected headers.
func (*Headers) GetProtected ¶
GetProtected returns the header with the given key from protected headers.
func (*Headers) Set ¶
Set sets the header with the given key in unprotected headers. `alg` and `crit` will always be set in protected headers.
func (*Headers) SetProtected ¶
SetProtected sets the header with the given key in protected headers.
type Message ¶
type Message interface { // GetMessageTag returns the COSE message tag. GetMessageTag() uint64 // GetContent returns the message content. GetContent() []byte // SetContent sets the message content. SetContent([]byte) }
Message represents a COSE message.
type Sign1Message ¶
type Sign1Message struct { Headers *Headers // contains filtered or unexported fields }
Sign1Message represents a COSE_Sign1 message.
func NewSign1Message ¶
func NewSign1Message() *Sign1Message
NewSign1Message creates a new Sign1Message instance.
func (*Sign1Message) GetContent ¶
func (m *Sign1Message) GetContent() []byte
GetContent returns the message content.
func (*Sign1Message) GetMessageTag ¶
func (m *Sign1Message) GetMessageTag() uint64
GetMessageTag returns the COSE_Sign1 message tag.
func (*Sign1Message) SetContent ¶
func (m *Sign1Message) SetContent(content []byte)
SetContent sets the message content.
func (*Sign1Message) SetSigner ¶ added in v0.2.0
func (m *Sign1Message) SetSigner(signer *Signer)
SetSigner sets the signer.
type SignMessage ¶ added in v0.2.0
type SignMessage struct { Headers *Headers // contains filtered or unexported fields }
SignMessage represents a COSE_Sign message.
func NewSignMessage ¶ added in v0.2.0
func NewSignMessage() *SignMessage
NewSignMessage creates a new SignMessage instance.
func (*SignMessage) AddSigner ¶ added in v0.2.0
func (m *SignMessage) AddSigner(signer *Signer)
AddSigner adds a signer for the message.
func (*SignMessage) GetContent ¶ added in v0.2.0
func (m *SignMessage) GetContent() []byte
GetContent returns the message content.
func (*SignMessage) GetMessageTag ¶ added in v0.2.0
func (m *SignMessage) GetMessageTag() uint64
GetMessageTag returns the COSE_Sign message tag.
func (*SignMessage) SetContent ¶ added in v0.2.0
func (m *SignMessage) SetContent(content []byte)
SetContent sets the message content.
type Signer ¶
type Signer struct { Headers *Headers // contains filtered or unexported fields }
Signer represents a signer with a private key and algorithm.
func NewSigner ¶
func NewSigner(alg Algorithm, key crypto.PrivateKey) (*Signer, error)
NewSigner creates a new signer with a private key and algorithm.
func (*Signer) GetHeaders ¶
GetHeader returns the headers for message signature.
func (*Signer) GetPrivateKey ¶ added in v0.2.0
func (s *Signer) GetPrivateKey() crypto.PrivateKey
GetPrivateKey returns the private key used by the signer.
func (*Signer) ToVerifier ¶
ToVerifier returns the public key verifier for the signer.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}
Verifier is a public key container for verifying COSE signatures.
func NewVerifier ¶
NewVerifier creates a new verifier from a public key and algorithm.
func (*Verifier) GetPublicKey ¶ added in v0.2.0
GetPublicKey returns the public key used by the verifier.