Documentation
¶
Index ¶
- Constants
- type Encrypt0Message
- func (m *Encrypt0Message[T]) Bytesify() []byte
- func (m *Encrypt0Message[T]) Decrypt(encryptor key.Encryptor, externalData []byte) error
- func (m *Encrypt0Message[T]) Encrypt(encryptor key.Encryptor, externalData []byte) error
- func (m *Encrypt0Message[T]) EncryptAndEncode(encryptor key.Encryptor, externalData []byte) ([]byte, error)
- func (m *Encrypt0Message[T]) MarshalCBOR() ([]byte, error)
- func (m *Encrypt0Message[T]) UnmarshalCBOR(data []byte) error
- type Headers
- func (h Headers) Bytesify() []byte
- func (h Headers) GetBytes(k key.IntKey) ([]byte, error)
- func (h Headers) GetInt(k key.IntKey) (int64, error)
- func (h Headers) GetSmallInt(k key.IntKey) (int, error)
- func (h Headers) GetString(k key.IntKey) (string, error)
- func (h Headers) GetUint(k key.IntKey) (uint64, error)
- func (h Headers) MarshalCBOR() ([]byte, error)
- type Mac0Message
- func (m *Mac0Message[T]) Bytesify() []byte
- func (m *Mac0Message[T]) Compute(macer key.MACer, externalData []byte) error
- func (m *Mac0Message[T]) ComputeAndEncode(macer key.MACer, externalData []byte) ([]byte, error)
- func (m *Mac0Message[T]) MarshalCBOR() ([]byte, error)
- func (m *Mac0Message[T]) Tag() []byte
- func (m *Mac0Message[T]) UnmarshalCBOR(data []byte) error
- func (m *Mac0Message[T]) Verify(macer key.MACer, externalData []byte) error
- type Sign1Message
- func (m *Sign1Message[T]) Bytesify() []byte
- func (m *Sign1Message[T]) MarshalCBOR() ([]byte, error)
- func (m *Sign1Message[T]) SignAndEncode(signer key.Signer, externalData []byte) ([]byte, error)
- func (m *Sign1Message[T]) Signature() []byte
- func (m *Sign1Message[T]) UnmarshalCBOR(data []byte) error
- func (m *Sign1Message[T]) Verify(verifier key.Verifier, externalData []byte) error
- func (m *Sign1Message[T]) WithSign(signer key.Signer, externalData []byte) error
- type SignMessage
- func (m *SignMessage[T]) Bytesify() []byte
- func (m *SignMessage[T]) MarshalCBOR() ([]byte, error)
- func (m *SignMessage[T]) SignAndEncode(signers key.Signers, externalData []byte) ([]byte, error)
- func (m *SignMessage[t]) Signatures() []*Signature
- func (m *SignMessage[T]) UnmarshalCBOR(data []byte) error
- func (m *SignMessage[T]) Verify(verifiers key.Verifiers, externalData []byte) error
- func (m *SignMessage[T]) WithSign(signers key.Signers, externalData []byte) error
- type Signature
Constants ¶
const ( HeaderLabelReserved key.IntKey = 0 HeaderLabelAlgorithm key.IntKey = 1 // protected header HeaderLabelCritical key.IntKey = 2 // protected header HeaderLabelContentType key.IntKey = 3 // unprotected header HeaderLabelKeyID key.IntKey = 4 // unprotected header HeaderLabelIV key.IntKey = 5 // unprotected header HeaderLabelPartialIV key.IntKey = 6 // unprotected header HeaderLabelCounterSignature key.IntKey = 7 // unprotected header HeaderLabelCounterSignature0 key.IntKey = 9 // unprotected header )
COSE Header labels registered in the IANA "COSE Header Parameters" registry.
Reference https://www.iana.org/assignments/cose/cose.xhtml#header-parameters
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Encrypt0Message ¶
type Encrypt0Message[T any] struct { Protected Headers Unprotected Headers Payload T // Payload should be set for encrypting // Ciphertext will be set after encrypting // or should be set for decrypting when DetachedCiphertext is true. Ciphertext []byte // If set to true, Ciphertext will not be encode into CBOR bytes. // Reference https://datatracker.ietf.org/doc/html/rfc9052#name-enveloped-cose-structure DetachedCiphertext bool // contains filtered or unexported fields }
Encrypt0Message represents a COSE_Encrypt0 object.
Reference https://datatracker.ietf.org/doc/html/rfc9052#name-single-recipient-encrypted
func DecryptEncrypt0Message ¶ added in v0.4.0
func DecryptEncrypt0Message[T any](encryptor key.Encryptor, coseData, externalData []byte) (*Encrypt0Message[T], error)
DecryptEncrypt0Message decrypts and decodes a COSE_Encrypt0 message with a Encryptor and returns a *Encrypt0Message. `externalData` should be the same as the one used in `Encrypt0Message.EncryptAndEncode`.
func (*Encrypt0Message[T]) Bytesify ¶
func (m *Encrypt0Message[T]) Bytesify() []byte
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (*Encrypt0Message[T]) Decrypt ¶
func (m *Encrypt0Message[T]) Decrypt(encryptor key.Encryptor, externalData []byte) error
Decrypt decrypts a COSE_Encrypt0 message with a Encryptor. It should call `Encrypt0Message.UnmarshalCBOR` before calling this method. `externalData` should be the same as the one used in Encrypt0Message.Encrypt.
func (*Encrypt0Message[T]) Encrypt ¶
func (m *Encrypt0Message[T]) Encrypt(encryptor key.Encryptor, externalData []byte) error
Encrypt encrypt a COSE_Encrypt0 message with a Encryptor. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*Encrypt0Message[T]) EncryptAndEncode ¶ added in v0.4.0
func (m *Encrypt0Message[T]) EncryptAndEncode(encryptor key.Encryptor, externalData []byte) ([]byte, error)
EncryptAndEncode encrypts and encodes a COSE_Encrypt0 message with a Encryptor. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*Encrypt0Message[T]) MarshalCBOR ¶
func (m *Encrypt0Message[T]) MarshalCBOR() ([]byte, error)
MarshalCBOR implements the CBOR Marshaler interface for Encrypt0Message. It should call `Encrypt0Message.Encrypt` before calling this method.
func (*Encrypt0Message[T]) UnmarshalCBOR ¶
func (m *Encrypt0Message[T]) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements the CBOR Unmarshaler interface for Mac0Message.
type Headers ¶
Headers represents a COSE Generic_Headers structure.
func (Headers) Bytesify ¶
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (Headers) 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 (Headers) GetInt ¶
GetInt 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 (Headers) GetSmallInt ¶
GetSmallInt returns the value for the key as an int in [-65536, 65536]. 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 [-65536, 65536], it returns (0, error).
func (Headers) 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).
func (Headers) GetUint ¶
GetUint returns the value for the key as an uint64. 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 (Headers) MarshalCBOR ¶
MarshalCBOR implements the CBOR Marshaler interface for Headers. It is the same as IntMap.MarshalCBOR.
type Mac0Message ¶
type Mac0Message[T any] struct { Protected Headers Unprotected Headers Payload T // contains filtered or unexported fields }
Mac0Message represents a COSE_Mac0 object.
Reference https://datatracker.ietf.org/doc/html/rfc9052#name-signing-with-one-signer
func VerifyMac0Message ¶
func VerifyMac0Message[T any](macer key.MACer, coseData, externalData []byte) (*Mac0Message[T], error)
VerifyMac0Message verifies and decodes a COSE_Mac0 message with a MACer and returns a *Mac0Message. `externalData` should be the same as the one used in `Mac0Message.ComputeAndEncode`.
func (*Mac0Message[T]) Bytesify ¶
func (m *Mac0Message[T]) Bytesify() []byte
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (*Mac0Message[T]) Compute ¶
func (m *Mac0Message[T]) Compute(macer key.MACer, externalData []byte) error
Compute computes a COSE_Mac0 message' MAC with a MACer. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*Mac0Message[T]) ComputeAndEncode ¶
ComputeAndEncode computes and encodes a COSE_Mac0 message with a MACer. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*Mac0Message[T]) MarshalCBOR ¶
func (m *Mac0Message[T]) MarshalCBOR() ([]byte, error)
MarshalCBOR implements the CBOR Marshaler interface for Mac0Message. It should call `Mac0Message.WithSign` before calling this method.
func (*Mac0Message[T]) Tag ¶
func (m *Mac0Message[T]) Tag() []byte
Tag returns the MAC tag of the Mac0Message. If the MAC is not computed, it returns nil.
func (*Mac0Message[T]) UnmarshalCBOR ¶
func (m *Mac0Message[T]) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements the CBOR Unmarshaler interface for Mac0Message.
func (*Mac0Message[T]) Verify ¶
func (m *Mac0Message[T]) Verify(macer key.MACer, externalData []byte) error
Verify verifies a COSE_Mac0 message' MAC with a MACer. It should call `Mac0Message.UnmarshalCBOR` before calling this method. `externalData` should be the same as the one used in Mac0Message.Compute.
type Sign1Message ¶
type Sign1Message[T any] struct { Protected Headers Unprotected Headers Payload T // contains filtered or unexported fields }
Sign1Message represents a COSE_Sign1 object.
Reference https://datatracker.ietf.org/doc/html/rfc9052#name-signing-with-one-signer
func VerifySign1Message ¶
func VerifySign1Message[T any](verifier key.Verifier, coseData, externalData []byte) (*Sign1Message[T], error)
VerifySign1Message verifies and decodes a COSE_Sign1 message with a Verifier and returns a *Sign1Message. `externalData` should be the same as the one used in `Sign1Message.SignAndEncode`.
func (*Sign1Message[T]) Bytesify ¶
func (m *Sign1Message[T]) Bytesify() []byte
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (*Sign1Message[T]) MarshalCBOR ¶
func (m *Sign1Message[T]) MarshalCBOR() ([]byte, error)
MarshalCBOR implements the CBOR Marshaler interface for Sign1Message. It should call `Sign1Message.WithSign` before calling this method.
func (*Sign1Message[T]) SignAndEncode ¶
SignAndEncode signs and encodes a COSE_Sign1 message with a Signer. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*Sign1Message[T]) Signature ¶
func (m *Sign1Message[T]) Signature() []byte
Signature returns the signature of the Sign1Message. If the Sign1Message is not signed, it returns nil.
func (*Sign1Message[T]) UnmarshalCBOR ¶
func (m *Sign1Message[T]) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements the CBOR Unmarshaler interface for Sign1Message.
func (*Sign1Message[T]) Verify ¶
func (m *Sign1Message[T]) Verify(verifier key.Verifier, externalData []byte) error
Verify verifies a COSE_Sign1 message with a Verifier. It should call `Sign1Message.UnmarshalCBOR` before calling this method. `externalData` should be the same as the one used in `Sign1Message.WithSign`.
func (*Sign1Message[T]) WithSign ¶
func (m *Sign1Message[T]) WithSign(signer key.Signer, externalData []byte) error
WithSign signs a COSE_Sign1 message with a Signer. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
type SignMessage ¶
type SignMessage[T any] struct { Protected Headers Unprotected Headers Payload T // contains filtered or unexported fields }
SignMessage represents a COSE_Sign object.
Reference https://datatracker.ietf.org/doc/html/rfc9052#name-signing-with-one-or-more-si
func VerifySignMessage ¶
func VerifySignMessage[T any](verifiers key.Verifiers, coseData, externalData []byte) (*SignMessage[T], error)
VerifySignMessage verifies and decodes a COSE_Sign format with some Verifiers and returns a *SignMessage. `externalData` should be the same as the one used in `SignMessage.SignAndEncode`.
func (*SignMessage[T]) Bytesify ¶
func (m *SignMessage[T]) Bytesify() []byte
Bytesify returns a CBOR-encoded byte slice. It returns nil if MarshalCBOR failed.
func (*SignMessage[T]) MarshalCBOR ¶
func (m *SignMessage[T]) MarshalCBOR() ([]byte, error)
MarshalCBOR implements the CBOR Marshaler interface for SignMessage. It should call `SignMessage.WithSign` before calling this method.
func (*SignMessage[T]) SignAndEncode ¶
SignAndEncode signs and encodes a COSE_Sign message with some Signers. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
func (*SignMessage[t]) Signatures ¶
func (m *SignMessage[t]) Signatures() []*Signature
Signatures returns the signatures of the SignMessage. If the SignMessage is not signed, it returns nil.
func (*SignMessage[T]) UnmarshalCBOR ¶
func (m *SignMessage[T]) UnmarshalCBOR(data []byte) error
UnmarshalCBOR implements the CBOR Unmarshaler interface for SignMessage.
func (*SignMessage[T]) Verify ¶
func (m *SignMessage[T]) Verify(verifiers key.Verifiers, externalData []byte) error
Verify verifies a COSE_Sign message with some Verifiers. It should call `SignMessage.UnmarshalCBOR` before calling this method. `externalData` should be the same as the one used in SignMessage.WithSign.
func (*SignMessage[T]) WithSign ¶
func (m *SignMessage[T]) WithSign(signers key.Signers, externalData []byte) error
WithSign signs a COSE_Sign message with some Signers. `externalData` can be nil. https://datatracker.ietf.org/doc/html/rfc9052#name-externally-supplied-data
type Signature ¶
type Signature struct {
Protected Headers
Unprotected Headers
// contains filtered or unexported fields
}
Signature represents a COSE_Signature object.
func (*Signature) Kid ¶
Kid returns the kid of the Signature which key signed. If the SignMessage is not signed, it returns nil.
func (*Signature) MarshalCBOR ¶
MarshalCBOR implements the CBOR Marshaler interface for Signature.
func (*Signature) Signature ¶
Signature returns the signature of the Signature. If the SignMessage is not signed, it returns nil.
func (*Signature) UnmarshalCBOR ¶
UnmarshalCBOR implements the CBOR Unmarshaler interface for Signature.