How contentauth/c2pa-rs works
Project type and purpose
• This is a Rust-based, multi-crate workspace whose primary deliverable is the c2pa library (implementing the C2PA and CAWG identity assertions spec).
• It also ships a high-level Rust SDK (sdk crate), a C FFI layer (c_api crate), a CLI tool (cli crate), plus auxiliary utilities (export_schema, make_test_images) and WASM support.
Top-level components (crates)
• Core Rust library (root Cargo.toml, workspace index).
• sdk crate: the heart of the implementation—modules for claims, manifests, asset handlers, cryptography, identity, JUMBF, I/O, validation, utilities.
• c_api crate: C-compatible bindings wrapping core library functions for use from C/C++.
• cli crate: command-line interface that invokes core library operations (read/write manifests, sign, validate).
• export_schema crate: generates JSON schemas for manifests.
• make_test_images crate: utility to derive test assets (thumbnails, manifests embedded in images).
• WASM/WebAssembly validator (sdk/src/wasm/webcrypto_validator.rs).
• Tests and examples: integration tests, fixtures, sample code under each crate.
Relationships and data flows
• CLI and C API both depend on the core library (c2pa / sdk crates).
• export_schema and make_test_images are standalone binaries that also depend on the core library modules.
• Core library exposes layered modules:
• Asset handlers (PNG, JPEG, PDF, MP3, etc.) → I/O → JUMBF processing → claim/manifest generation → signing (via cryptography module) → storage.
• Identity assertion builder/validator modules feed into manifest.
• Crypto module has two implementations (OpenSSL FFI + pure Rust).
• Validation engine (OCSP, time-stamp, COSE, raw signatures).
• WASM validator sits alongside the crypto module when targeting web.
Architectural patterns and design principles
• Modular, crate-per-concern design: each crate encapsulates a specific delivery or binding (e.g., CLI, C API, WASM).
• Layered domain model in sdk:
1. Domain types (claims, manifests, assertions)
2. Builders/generators
3. Crypto + signing/validation
4. Asset I/O
5. Utilities (CBOR, Merkle, XMP, thumbnailing)
• FFI abstraction: c_api surfaces a C interface over the Rust internals.
• Test harness with fixtures under each crate, ensuring coverage of formats and cryptographic workflows.