Skip to Content
oxcrypto

CMS

Sign and verify CMS SignedData (RFC 5652) with X.509 signer certificates.

Warning

Experimental: cms is a pre-release, pinned to 0.3.0-rc.2. Its API and behavior can change between pre-releases.

from oxcrypto.pki.cms import CMS

signed = CMS.SIGNED_DATA.sign(b"message", certificate=cert, private_key=key)
assert CMS.SIGNED_DATA.verify(signed, certificate=cert)
assert CMS.SIGNED_DATA.content(signed) == b"message"

sign(data, *, certificate, private_key, algorithm=None, detached=False, certificates=[]) returns a DER ContentInfo holding SignedData with one signer identified by issuer and serial number. The signed attributes carry the content type and message digest. The digest is the signature hash for RSA and ECDSA, and SHA-512 for Ed25519 (RFC 8419) and ML-DSA. certificate must match private_key; it and certificates are added to the SignedData. With detached=True the content is left out.

verify(signed_data, *, certificate, content=None) returns True if a signer identified by the certificate's issuer and serial number signed the content. Pass content for detached SignedData only. It checks the signature, the message digest and content type attributes, and nothing about the certificate itself; validate it with path validation. content(signed_data) returns the encapsulated content or None, and certificates(signed_data) returns the certificates carried in the message.

Signers identified by subject key identifier are skipped, and SignedData digests other than SHA-256, SHA-384 and SHA-512 do not verify.

Upstream

CrateStandardAudit
cms 0.3.0-rc.2 (pre-release)RFC 5652, RFC 8419No published audit

The crate builds with Rust 1.88, the oxcrypto MSRV. Tests use the detached signature from NIST PKITS 2011 S/MIME test SignedValidSignaturesTest1 and the OpenSSL-generated SignedData fixture from the RustCrypto cms tests.

On this page