# Synta C Bindings
Synta is a high-performance Rust ASN.1 library. This book documents its C
Foreign Function Interface (FFI) — a stable C ABI library named **`csynta`**
(`libcsynta.so` on Linux, `libcsynta.dylib` on macOS, `csynta.dll` on Windows).
The C header `include/synta.h` is generated automatically by
[cbindgen](https://github.com/mozilla/cbindgen) during the build.
## What the C bindings provide
The `csynta` library exposes the full synta ASN.1 encoder/decoder and a
comprehensive X.509 PKI parser to C and C++ programs:
- **Core ASN.1 codec** — `SyntaDecoder` and `SyntaEncoder` handles for all
ASN.1 primitive types (INTEGER, BOOLEAN, OCTET STRING, BIT STRING, OBJECT
IDENTIFIER, NULL, REAL), all string types (UTF8String, PrintableString,
IA5String), and all constructed types (SEQUENCE, SET, explicit/implicit tags).
- **X.509 PKI** — parse `SyntaCertificate`, `SyntaCrl` (RFC 5280),
`SyntaCsr` (RFC 2986), and `SyntaOcsp` (RFC 6960); extract certificates from
PKCS#7 and PKCS#12 archives; PEM encode/decode following RFC 7468.
- **CMS cryptography** — full RFC 5652 coverage: `ContentInfo` parser,
`SignedData`, `SignerInfo`, `EnvelopedData`, `DigestedData` inspection, and
`EncryptedData` encrypt/decrypt (AES-CBC, with the `openssl` feature).
- **Code generation** — `synta-codegen --lang c` generates complete C header
and implementation files from ASN.1 schemas, producing production-ready
`TypeName_decode`, `TypeName_encode`, and `TypeName_free` functions.
## Architecture
All heap allocations are performed inside the Rust runtime. The C API never
exposes raw Rust pointers that could be freed with `free(3)`. Each opaque
handle type has a dedicated `_free` function, and `SyntaByteArray` uses an
`owned` flag to distinguish borrowed spans from owned allocations that must be
released via `synta_byte_array_free()`.
Error information is stored in thread-local storage. Each thread has its own
independent error state; decoder and encoder handles are not thread-safe and
must not be shared across threads.
## How to navigate this book
- **[Installation and Linking](getting-started/installation.md)** — how to
build the library, link against it, and integrate with pkg-config or CMake.
- **[Quick Start](getting-started/quickstart.md)** — minimal decode and encode
examples you can compile and run immediately.
- **Code Generation** — how `synta-codegen --lang c` transforms ASN.1 schemas
into C structs, encode/decode functions, and build system files.
- **API Reference** — complete documentation for every exported function grouped
by area: errors, decoder, encoder, helper types, X.509 PKI, and CMS.
- **[Memory Management](memory.md)** — ownership rules, the `SyntaByteArray`
borrowed/owned contract, arena mode, and common pitfalls.
- **[Example Programs](examples/index.md)** — annotated list of standalone
example programs in `synta-ffi/examples/c/`.
For the Rust API, code-generation tutorial, and ASN.1 schema authoring see
the [Rust API book](https://codeberg.org/abbra/synta/src/branch/main/docs/rust/src/README.md).