Registry / auth-security / cose
library0.9.dev8pypypi✓ verified 85d ago

A pure Python implementation of CBOR Object Signing and Encryption (COSE) as defined in RFC 8152. Current version 0.9.dev8, pre-release with ongoing development. Cadence: irregular, pre-release.

pip install cose
INSTALL
IMPORT
SIG · COSE
C
cose
auth-securitypythonv0.9.dev8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CoseMessage
from cose.messages import CoseMessage
Correct import path.
CoseKey
from cose.keys import CoseKey
Correct import path.
EncryptMessage
from cose.messages import EncryptMessage
from cose import EncryptMessage
Common mistake: top-level import fails because EncryptMessage is in the messages submodule.

Create a simple EC2 key. For real use, provide proper key material.

from cose.keys import CoseKey from cose.keys.keyparam import KpKty, KpAlg, KpKeyOps from cose.keys.keytype import KtyEC2 from cose.keys.keyops import SignOp, VerifyOp, EncryptOp, DecryptOp from cose.algorithms import Es256 from cose.messages import EncryptMessage, SignMessage from cose.headers import Algorithm, ContentType # Create an EC2 key for signing import os private_key_bytes = os.urandom(32) # dummy for demo key = CoseKey.from_dict({ 'kty': KtyEC2, 'crv': 'P-256', 'x': os.urandom(32), 'y': os.urandom(32), 'd': private_key_bytes, 'alg': Es256, }) print(f"Created key: {key}")
Debug
Known issues
gotchaThe library is in pre-release (0.9.dev8). APIs may change without notice.
fix
Pin to a specific version and test compatibility.
affects: *
gotchaImports are deep: submodules like messages, keys, algorithms, headers are not exported at top level.
fix
Use full paths, e.g., from cose.messages import EncryptMessage.
affects: *
gotchaMany COSE objects require manual construction of key parameters and headers; no high-level helper for common patterns.
fix
Refer to the official RFC 8152 and library examples for correct parameter values.
affects: *
Errors
Common errors & fixes
ImportError: cannot import name 'EncryptMessage' from 'cose'
Trying to import from top-level package instead of submodule.
fix
Use: from cose.messages import EncryptMessage
AttributeError: module 'cose' has no attribute 'CoseKey'
CoseKey is in cose.keys, not in top-level cose.
fix
Use: from cose.keys import CoseKey
KeyError: 'kty'
Passing a dict with string keys instead of using the library's enum types.
fix
Use library types like KtyEC2 instead of strings: key = CoseKey.from_dict({'kty': KtyEC2, ...})
Upgrade
Version history
0.9.dev8latest on PyPI · released Jul 1, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources
cose — pip install cose · libregistry