synta 0.2.5

ASN.1 parser, decoder, and encoder library with DER/BER support and C FFI
Documentation
# Example Programs


Runnable examples are in `examples/` at the repository root.  Run any
example with:

```bash
cargo run --example <name>
```

Some examples require feature flags:

```bash
cargo run --example derive_usage --features derive
cargo run --example serde_usage  --features serde
cargo run --example serde_cert   --features serde
```

## 1. `decode_integer.rs` — Decode ASN.1 INTEGER values

[Source](decode_integer.md) · [`decode_integer.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/decode_integer.rs)

Decode DER-encoded INTEGER values using `Decoder` and the `Integer` type.
Covers positive and negative integers, big-integer handling, and the
`Encoding` trait.

## 2. `encode_sequence.rs` — Build and encode a SEQUENCE

[Source](encode_sequence.md) · [`encode_sequence.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/encode_sequence.rs)

Build a SEQUENCE containing INTEGER, BOOLEAN, and OCTET STRING fields,
then encode to DER.  Shows the `Encoder` API and round-trip verification
with `Decoder`.

## 3. `oid_usage.rs` — Working with Object Identifiers

[Source](oid_usage.md) · [`oid_usage.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/oid_usage.rs)

Create OIDs from dot-notation and arc components, encode and decode them,
compare OIDs, and look up well-known algorithm OIDs.

## 4. `parse_certificate.rs` — Parse an X.509 certificate structure

[Source](parse_certificate.md) · [`parse_certificate.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/parse_certificate.rs)

Navigate an X.509 certificate's ASN.1 structure using `Decoder` and
`Element`.  Extracts the TBSCertificate, issuer/subject names, serial
number, and validity period.

## 5. `derive_usage.rs` — Derive macros for ASN.1 structures

[Source](derive_usage.md) · [`derive_usage.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/derive_usage.rs)

Use the `synta-derive` macros (`Decode`, `Encode`, `Tagged`) to implement
DER codecs for custom Rust structs with zero boilerplate.  Covers
SEQUENCE, OPTIONAL fields, and tagged types.  Requires `--features derive`.

## 6. `serde_usage.rs` — Serde serialization of ASN.1 types

[Source](serde_usage.md) · [`serde_usage.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/serde_usage.rs)

Use the optional `serde` feature to convert synta's ASN.1 types (Integer,
OctetString, OID, Sequence, …) to and from JSON.  Documents the JSON
representation of each primitive type.  Requires `--features serde`.

## 7. `serde_cert.rs` — Serde serialization of an X.509 certificate

[Source](serde_cert.md) · [`serde_cert.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/serde_cert.rs)

Load a real PEM certificate from `tests/vectors/`, parse it into an
`Element` tree, serialize the tree to JSON, then deserialize and compare.
Requires `--features serde`.

## 8. `asn1parse.rs` — ASN.1 parser utility

[Source](asn1parse.md) · [`asn1parse.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/asn1parse.rs)

Command-line tool that reads PEM or DER files and prints a structured
ASN.1 tree similar to `openssl asn1parse`.  Useful for debugging encoded
data.  Run as: `cargo run --example asn1parse <file>`.

## 9. `generate_test_cert.rs` — Generate a test certificate

[Source](generate_test_cert.md) · [`generate_test_cert.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/generate_test_cert.rs)

Generate a structurally valid but cryptographically invalid X.509
certificate for use in parser test suites.  Outputs
`invalid_test_certificate.{pem,der}` in the current directory.

## 10. `profile_cert_parse.rs` — Certificate parsing profiling harness

[Source](profile_cert_parse.md) · [`profile_cert_parse.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/profile_cert_parse.rs)

Minimal binary for profiling the certificate decoder under `perf` or
Instruments.  Build in release mode and attach a profiler:
`cargo build --release --example profile_cert_parse`.

## 11. `sequenceof_benchmark.rs` — Element vs SequenceOf benchmark

[Source](sequenceof_benchmark.md) · [`sequenceof_benchmark.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/sequenceof_benchmark.rs)

Micro-benchmark comparing eager `Element`-based parsing against lazy
`SequenceOf` iteration for `SEQUENCE OF` structures.  Demonstrates the
O(1) lazy-parse advantage for large collections.

## 12. `name_constraints.rs` — NameConstraints extension (RFC 5280 §4.2.1.10)

[Source](name_constraints.md) · [`name_constraints.rs` on Codeberg](https://codeberg.org/abbra/synta/src/branch/main/examples/name_constraints.rs)

Demonstrates `NameConstraintsBuilder` from `synta_certificate`:

- Build a `NameConstraints` DER value with `permit_dns`, `exclude_dns`,
  `permit_ip`, `exclude_ip`, and `permit_rfc822`.
- Verify the raw DER output — confirm the `[0] IMPLICIT GeneralSubtrees`
  (permitted) and `[1] IMPLICIT GeneralSubtrees` (excluded) CONSTRUCTED
  context tags using a simple byte-level TLV walker.
- Show that `permit_*`-only and `exclude_*`-only calls produce DER with
  only the relevant IMPLICIT field present.
- Combine all constraint types in a single builder chain.