synta-python 0.3.1

Python extension module for the synta ASN.1 library
Documentation
//! Python bindings for KEM algorithm types (RFC 9629 / FIPS 203).
//!
//! Exposes ``KEMRecipientInfo`` and ``CMSORIforKEMOtherInfo`` (re-exported
//! from ``synta.cms``) and ML-KEM / CMS-KEM OID constants in the
//! ``synta.kem`` submodule.

use pyo3::prelude::*;

// Re-use the types already registered in synta.cms so they are available
// from synta.kem without duplicating the class implementations.
pub(super) use super::cms::kem::{PyCMSORIforKEMOtherInfo, PyKEMRecipientInfo};

// ── register_kem_submodule ────────────────────────────────────────────────────

/// Build and register the ``synta.kem`` submodule.
///
/// Exposes:
/// - :class:`KEMRecipientInfo` — the CMS-KEM recipient-info SEQUENCE (RFC 9629 §6.2)
/// - :class:`CMSORIforKEMOtherInfo` — the KDF context structure (RFC 9629 §6.2)
/// - ML-KEM (FIPS 203) OID constants: ``ID_ML_KEM_512``, ``ID_ML_KEM_768``,
///   ``ID_ML_KEM_1024``
/// - CMS-KEM OtherRecipientInfo OIDs: ``ID_ORI``, ``ID_ORI_KEM``
pub(super) fn register_kem_submodule(parent: &Bound<'_, PyModule>) -> PyResult<()> {
    let py = parent.py();
    let m = PyModule::new(py, "kem")?;

    // ── Parseable types ───────────────────────────────────────────────────────
    m.add_class::<PyKEMRecipientInfo>()?;
    m.add_class::<PyCMSORIforKEMOtherInfo>()?;

    // ── ML-KEM (FIPS 203) algorithm OIDs ─────────────────────────────────────
    m.add(
        "ID_ML_KEM_512",
        super::oid_const(py, synta_certificate::oids::ML_KEM_512),
    )?;
    m.add(
        "ID_ML_KEM_768",
        super::oid_const(py, synta_certificate::oids::ML_KEM_768),
    )?;
    m.add(
        "ID_ML_KEM_1024",
        super::oid_const(py, synta_certificate::oids::ML_KEM_1024),
    )?;

    // ── CMS-KEM OtherRecipientInfo OIDs (RFC 9629 §6.2) ──────────────────────
    m.add(
        "ID_ORI",
        super::oid_const(py, synta_certificate::cms_kem_types::ID_ORI),
    )?;
    m.add(
        "ID_ORI_KEM",
        super::oid_const(py, synta_certificate::cms_kem_types::ID_ORI_KEM),
    )?;

    crate::install_submodule(
        parent,
        &m,
        "synta.kem",
        Some(concat!(
            "synta.kem — KEM algorithm types (RFC 9629 / FIPS 203).\n\n",
            "Provides KEMRecipientInfo and CMSORIforKEMOtherInfo for decoding\n",
            "quantum-safe KEM recipient structures from CMS EnvelopedData, along\n",
            "with ML-KEM (FIPS 203) and CMS-KEM OID constants.\n\n",
            "The KEMRecipientInfo SEQUENCE is carried as an OtherRecipientInfo\n",
            "alternative inside CMS EnvelopedData, identified by id-ori-kem\n",
            "(1.2.840.113549.1.9.16.13.3).",
        )),
    )
}