synta 0.3.1

ASN.1 parser, decoder, and encoder library with DER/BER support and C FFI
Documentation
"""
Synta: High-performance ASN.1 parser and encoder for Python

This module provides ASN.1 parsing, decoding, and encoding capabilities
with support for DER (Distinguished Encoding Rules) and BER (Basic Encoding Rules).

Example:
    >>> import synta
    >>> # Decode an integer
    >>> decoder = synta.Decoder(b'\\x02\\x01\\x2A', synta.Encoding.DER)
    >>> integer = decoder.decode_integer()
    >>> print(integer.to_int())
    42

    >>> # Encode data
    >>> encoder = synta.Encoder(synta.Encoding.DER)
    >>> encoder.encode_integer(42)
    >>> output = encoder.finish()

    >>> # Parse X.509 certificates
    >>> with open('cert.der', 'rb') as f:
    ...     cert = synta.Certificate.from_der(f.read())
    ...     print(f"Subject: {cert.subject}")
"""

from synta._synta import (
    # Encoding
    Encoding,

    # Core classes
    Decoder,
    Encoder,

    # Primitive types
    Integer,
    OctetString,
    ObjectIdentifier,
    RelativeOid,
    BitString,
    Boolean,
    Real,
    UtcTime,
    GeneralizedTime,
    Null,
    Utf8String,
    PrintableString,
    IA5String,
    NumericString,
    TeletexString,
    VisibleString,
    GeneralString,
    UniversalString,
    BmpString,

    # Generic / fallback types
    RawElement,

    # Certificate / PKI types
    AlgorithmIdentifier,
    Certificate,
    CertificationRequest,
    CertificateList,
    OCSPResponse,
    OCSPRequest,
    CertID,

    # Crypto key types
    PrivateKey,
    PublicKey,

    # Certificate / PKI parsed types
    PolicyInformation,
    PolicyQualifier,

    # Certificate / CSR / CRL / OCSP builders
    CertificateBuilder,
    CsrBuilder,
    NameBuilder,
    CertificateListBuilder,
    OCSPResponseBuilder,
    OCSPSingleResponse,
    OCSPCertIDSpec,
    OCSPRequestBuilder,

    # RFC 3161 Time-Stamp Protocol
    TimeStampReqBuilder,
    TimeStampResp,

    # RFC 2634 Extended Security Services builders
    SigningCertificateBuilder,
    ReceiptRequestBuilder,
    ESSSecurityLabelBuilder,

    # RFC 9399 Logotype extension builder
    LogotypeExtnBuilder,

    # RFC 7773 ACE-88 Authentication Context builder
    AuthenticationContextsBuilder,

    # ML-DSA / RSA key types
    MlDsaPrivateKey,
    MlDsaPublicKey,
    RsaPublicKey,
    RsassaPssParams,

    # Generic / tagged element type
    TaggedElement,

    # PEM helpers
    pem_to_der,
    der_to_pem,

    # PKCS#7 / PKCS#12 loaders and builders
    load_der_pkcs7_certificates,
    load_pem_pkcs7_certificates,
    load_pkcs12_certificates,
    load_pkcs12_keys,
    load_pkcs12,
    read_pki_blocks,
    create_pkcs12,

    # X.509 structure helpers
    parse_general_names,
    parse_name_attrs,
    encode_subject_alt_names,
    encode_extended_key_usage,
    name_der_equal,
    digest,

    # Name / DN helpers
    format_dn,
    format_dn_slash,

    # Extension / SPKI helpers
    find_extension_value,
    encode_general_names,
    signing_algorithm_der,
    key_usage_bit,
    decode_public_key_info,

    # Exceptions
    SyntaError,

    # Version
    __version__,
)

__all__ = [
    # Encoding
    "Encoding",

    # Core classes
    "Decoder",
    "Encoder",

    # Primitive types
    "Integer",
    "OctetString",
    "ObjectIdentifier",
    "RelativeOid",
    "BitString",
    "Boolean",
    "Real",
    "UtcTime",
    "GeneralizedTime",
    "Null",
    "Utf8String",
    "PrintableString",
    "IA5String",
    "NumericString",
    "TeletexString",
    "VisibleString",
    "GeneralString",
    "UniversalString",
    "BmpString",

    # Generic / fallback types
    "RawElement",

    # Certificate / PKI types
    "AlgorithmIdentifier",
    "Certificate",
    "CertificationRequest",
    "CertificateList",
    "OCSPResponse",
    "OCSPRequest",
    "CertID",

    # Crypto key types
    "PrivateKey",
    "PublicKey",

    # Certificate / PKI parsed types
    "PolicyInformation",
    "PolicyQualifier",

    # Certificate / CSR / CRL / OCSP builders
    "CertificateBuilder",
    "CsrBuilder",
    "NameBuilder",
    "CertificateListBuilder",
    "OCSPResponseBuilder",
    "OCSPSingleResponse",
    "OCSPCertIDSpec",
    "OCSPRequestBuilder",

    # RFC 3161 Time-Stamp Protocol
    "TimeStampReqBuilder",
    "TimeStampResp",

    # RFC 2634 Extended Security Services builders
    "SigningCertificateBuilder",
    "ReceiptRequestBuilder",
    "ESSSecurityLabelBuilder",

    # RFC 9399 Logotype extension builder
    "LogotypeExtnBuilder",

    # RFC 7773 ACE-88 Authentication Context builder
    "AuthenticationContextsBuilder",

    # ML-DSA / RSA key types
    "MlDsaPrivateKey",
    "MlDsaPublicKey",
    "RsaPublicKey",
    "RsassaPssParams",

    # Generic / tagged element type
    "TaggedElement",

    # PEM helpers
    "pem_to_der",
    "der_to_pem",

    # PKCS#7 / PKCS#12 loaders and builders
    "load_der_pkcs7_certificates",
    "load_pem_pkcs7_certificates",
    "load_pkcs12_certificates",
    "load_pkcs12_keys",
    "load_pkcs12",
    "read_pki_blocks",
    "create_pkcs12",

    # X.509 structure helpers
    "parse_general_names",
    "parse_name_attrs",
    "encode_subject_alt_names",
    "encode_extended_key_usage",
    "name_der_equal",
    "digest",

    # Name / DN helpers
    "format_dn",
    "format_dn_slash",

    # Extension / SPKI helpers
    "find_extension_value",
    "encode_general_names",
    "signing_algorithm_der",
    "key_usage_bit",
    "decode_public_key_info",

    # Exceptions
    "SyntaError",

    # Version
    "__version__",

    # Pure-Python schema module
    "schema",

    # Submodules
    "ac",
    "acme",
    "cms",
    "cmp",
    "crmf",
    "crypto",
    "ext",
    "general_name",
    "kem",
    "krb5",
    "ms_pki",
    "mtc",
    "oids",
    "pkcs5",
    "pkcs8",
    "pkcs9",
    "pkcs11",
    "pkixalgs",
    "spnego",
    "x509",
]

# Expose submodules so they are accessible without an explicit sub-import.
# The Rust extension already registered each one in sys.modules and set it
# as an attribute on _synta during `from synta._synta import ...` above.
from synta._synta import ac  # noqa: F401
from synta._synta import acme  # noqa: F401
from synta._synta import cms  # noqa: F401
from synta._synta import cmp  # noqa: F401
from synta._synta import crmf  # noqa: F401
from synta._synta import crypto  # noqa: F401
from synta._synta import ext  # noqa: F401
from synta._synta import general_name  # noqa: F401
from synta._synta import kem  # noqa: F401
from synta._synta import ms_pki  # noqa: F401
from synta._synta import oids  # noqa: F401
from synta._synta import pkcs5  # noqa: F401
from synta._synta import pkcs8  # noqa: F401
from synta._synta import pkcs9  # noqa: F401
from synta._synta import pkixalgs  # noqa: F401
from synta._synta import x509  # noqa: F401

# Load subsystem extension modules — each must be imported AFTER _synta so
# that synta.ObjectIdentifier and synta.SyntaError are already in sys.modules.
# These extensions are optional; if their Rust .so is absent (e.g. in a
# documentation-only install), import synta must still succeed.
from synta import schema as schema  # noqa: F401  — pure-Python ASN.1 schema decorators

import sys as _sys
try:
    import synta._krb5  # noqa: F401  — registers synta.krb5 and synta.spnego
    import synta._mtc   # noqa: F401  — registers synta.mtc in sys.modules
except ImportError:
    pass
krb5   = _sys.modules.get("synta.krb5")
mtc    = _sys.modules.get("synta.mtc")
spnego = _sys.modules.get("synta.spnego")

try:
    from synta._synta import pkcs11  # noqa: F401  — registers synta.pkcs11
except ImportError:
    pass
pkcs11 = _sys.modules.get("synta.pkcs11")