Skip to main content

_synta/certificate/
kem.rs

1//! Python bindings for KEM algorithm types (RFC 9629 / FIPS 203).
2//!
3//! Exposes ``KEMRecipientInfo`` and ``CMSORIforKEMOtherInfo`` (re-exported
4//! from ``synta.cms``) and ML-KEM / CMS-KEM OID constants in the
5//! ``synta.kem`` submodule.
6
7use pyo3::prelude::*;
8
9// Re-use the types already registered in synta.cms so they are available
10// from synta.kem without duplicating the class implementations.
11pub(super) use super::cms::kem::{PyCMSORIforKEMOtherInfo, PyKEMRecipientInfo};
12
13// ── register_kem_submodule ────────────────────────────────────────────────────
14
15/// Build and register the ``synta.kem`` submodule.
16///
17/// Exposes:
18/// - :class:`KEMRecipientInfo` — the CMS-KEM recipient-info SEQUENCE (RFC 9629 §6.2)
19/// - :class:`CMSORIforKEMOtherInfo` — the KDF context structure (RFC 9629 §6.2)
20/// - ML-KEM (FIPS 203) OID constants: ``ID_ML_KEM_512``, ``ID_ML_KEM_768``,
21///   ``ID_ML_KEM_1024``
22/// - CMS-KEM OtherRecipientInfo OIDs: ``ID_ORI``, ``ID_ORI_KEM``
23pub(super) fn register_kem_submodule(parent: &Bound<'_, PyModule>) -> PyResult<()> {
24    let py = parent.py();
25    let m = PyModule::new(py, "kem")?;
26
27    // ── Parseable types ───────────────────────────────────────────────────────
28    m.add_class::<PyKEMRecipientInfo>()?;
29    m.add_class::<PyCMSORIforKEMOtherInfo>()?;
30
31    // ── ML-KEM (FIPS 203) algorithm OIDs ─────────────────────────────────────
32    m.add(
33        "ID_ML_KEM_512",
34        super::oid_const(py, synta_certificate::oids::ML_KEM_512),
35    )?;
36    m.add(
37        "ID_ML_KEM_768",
38        super::oid_const(py, synta_certificate::oids::ML_KEM_768),
39    )?;
40    m.add(
41        "ID_ML_KEM_1024",
42        super::oid_const(py, synta_certificate::oids::ML_KEM_1024),
43    )?;
44
45    // ── CMS-KEM OtherRecipientInfo OIDs (RFC 9629 §6.2) ──────────────────────
46    m.add(
47        "ID_ORI",
48        super::oid_const(py, synta_certificate::cms_kem_types::ID_ORI),
49    )?;
50    m.add(
51        "ID_ORI_KEM",
52        super::oid_const(py, synta_certificate::cms_kem_types::ID_ORI_KEM),
53    )?;
54
55    crate::install_submodule(
56        parent,
57        &m,
58        "synta.kem",
59        Some(concat!(
60            "synta.kem — KEM algorithm types (RFC 9629 / FIPS 203).\n\n",
61            "Provides KEMRecipientInfo and CMSORIforKEMOtherInfo for decoding\n",
62            "quantum-safe KEM recipient structures from CMS EnvelopedData, along\n",
63            "with ML-KEM (FIPS 203) and CMS-KEM OID constants.\n\n",
64            "The KEMRecipientInfo SEQUENCE is carried as an OtherRecipientInfo\n",
65            "alternative inside CMS EnvelopedData, identified by id-ori-kem\n",
66            "(1.2.840.113549.1.9.16.13.3).",
67        )),
68    )
69}