Skip to Content
oxcrypto

COSE

CBOR Object Signing and Encryption messages and keys (RFC 9052, RFC 9053).

oxcrypto.cose builds and parses tagged COSE messages with the coset crate 0.4.2, which handles only the CBOR structure. Signatures, MACs and AEAD encryption run on the same oxcrypto primitives as JOSE.

Each operation takes the algorithm as a selector. Decoding requires that:

  • the message carries the expected CBOR tag (COSE_Sign1 18, COSE_Sign 98, COSE_Mac0 17, COSE_Encrypt0 16);
  • alg is in the protected header and equals the selector; an alg in the unprotected header, a missing alg or a crit header raises ValueError, and a different alg raises InvalidTag;
  • the payload or ciphertext is attached; detached content raises ValueError.

A key of the wrong type for the selector raises TypeError. A failed signature, MAC or decryption raises InvalidTag, and verify* returns False instead. Malformed CBOR raises ValueError. Optional kid values are written to the unprotected header, and external_aad is bound into the Sig_structure, MAC_structure or Enc_structure.

Formats

Upstream

CrateStandardAudit
coset 0.4.2 on ciboriumRFC 9052, RFC 9053 (CBOR structures only)No published audit

Tests use the cose-wg/Examples messages whose algorithm is in the protected header and whose key is direct, including their failure cases.

Zeroization

COSE adds no long-lived key objects. AEAD and MAC keys are Python bytes and are not wiped. Decrypted plaintext is held in a wiped buffer until the returned bytes are created, and private COSE_Key members are encoded from borrowed buffers. Private COSE_Key parsing wipes the decoded CBOR byte and text values managed by oxcrypto. Stack copies made by the AES, ChaCha20, HMAC, RSA and curve crates remain outside that coverage.

Treat zeroization as defense in depth. It does not guarantee that secrets are gone from process memory.

On this page