synta 0.1.5

ASN.1 parser, decoder, and encoder library with DER/BER support and C FFI
Documentation
# RFC 3279 Algorithm Parameters


`synta.pkixalgs` provides types for decoding DSA/DH domain parameters and DSA/ECDSA
signature values, as defined in RFC 3279.

```python
import synta.pkixalgs as pa
```

## DssParms

DSA domain parameters (RFC 3279 §2.3.2). Decoded from the `parameters` field of an
`AlgorithmIdentifier` whose OID is `id-dsa`.

```python
class DssParms:
    @staticmethod
    def from_der(data: bytes) -> DssParms: ...
    def to_der(self) -> bytes: ...
    p: bytes    # prime modulus (big-endian two's-complement)
    q: bytes    # prime divisor
    g: bytes    # generator
```

## DssSigValue

DSA signature value (RFC 3279 §2.2.2). Contains the `(r, s)` integer pair.

```python
class DssSigValue:
    @staticmethod
    def from_der(data: bytes) -> DssSigValue: ...
    def to_der(self) -> bytes: ...
    r: bytes    # signature integer r (big-endian two's-complement)
    s: bytes    # signature integer s
```

## EcdsaSigValue

ECDSA signature value (RFC 3279 §2.2.3, X9.62). Contains the `(r, s)` integer pair.

```python
class EcdsaSigValue:
    @staticmethod
    def from_der(data: bytes) -> EcdsaSigValue: ...
    def to_der(self) -> bytes: ...
    r: bytes
    s: bytes
```

## ECParameters

EC domain parameters CHOICE (RFC 3279 §2.3.5, X9.62). Represents the three-arm CHOICE:
`namedCurve` (OID), `ecParameters` (explicit domain params), or `implicitlyCA` (NULL).

```python
class ECParameters:
    @staticmethod
    def from_der(data: bytes) -> ECParameters: ...
    def to_der(self) -> bytes: ...
    arm: str                              # "namedCurve", "ecParameters", or "implicitlyCA"
    named_curve_oid: ObjectIdentifier | None  # None if arm is not "namedCurve"
```

## OID constants

| Constant | OID | Description |
|---|---|---|
| `ID_DSA` | `1.2.840.10040.4.1` | DSA public key |
| `ID_DSA_WITH_SHA1` | `1.2.840.10040.4.3` | DSA with SHA-1 signature |
| `DHPUBLICNUMBER` | `1.2.840.10046.2.1` | Diffie-Hellman public key |
| `ID_EC_PUBLIC_KEY` | `1.2.840.10045.2.1` | EC public key |
| `ECDSA_WITH_SHA1` | `1.2.840.10045.4.1` | ECDSA with SHA-1 |
| `ECDSA_WITH_SHA256` | `1.2.840.10045.4.3.2` | ECDSA with SHA-256 |
| `ECDSA_WITH_SHA384` | `1.2.840.10045.4.3.3` | ECDSA with SHA-384 |
| `ECDSA_WITH_SHA512` | `1.2.840.10045.4.3.4` | ECDSA with SHA-512 |
| `PRIME192V1` | `1.2.840.10045.3.1.1` | NIST P-192 / secp192r1 |
| `PRIME256V1` | `1.2.840.10045.3.1.7` | NIST P-256 / secp256r1 |
| `SECP224R1` | `1.3.132.0.33` | NIST P-224 |
| `SECP384R1` | `1.3.132.0.34` | NIST P-384 |
| `SECP521R1` | `1.3.132.0.35` | NIST P-521 |

## Usage

```python
import synta
import synta.pkixalgs as pa

# Decode ECDSA signature value from cert.signature_value
sig = pa.EcdsaSigValue.from_der(cert.signature_value)
print(f"r: {sig.r.hex()}")
print(f"s: {sig.s.hex()}")

# Decode EC curve OID from public key algorithm parameters
if cert.public_key_algorithm_params:
    ec_params = pa.ECParameters.from_der(cert.public_key_algorithm_params)
    if ec_params.arm == "namedCurve":
        print(f"curve OID: {ec_params.named_curve_oid}")
```