How contentauth/c2pa-c works
Project type and purpose
• This is an open-source C++ library (c2pa_cpp) that exposes C and C++ APIs for reading, validating, and writing C2PA manifests inside media files.
• It sits as a wrapper around a set of pre-built dynamic libraries from the c2pa-rs (Rust) implementation, providing a CMake-friendly interface for C++ applications.
File structure
• Top-level build/config:
• CMakeLists.txt, Makefile – orchestrate building the core library, examples, and tests.
• .github/workflows/*.yml – CI pipelines for linting, building, testing, and release.
• Core library:
• /c2pa.hpp – public C++ header API.
• src/c2pa.cpp – implementation wrapping calls into the Rust dynamic libraries.
• Examples:
• examples/demo.cpp, training.cpp – sample apps showing read/validate and write workflows.
• examples/CMakeLists.txt – build scripts for the samples.
• Tests:
• tests/*.cpp, tests/fixtures – unit and integration tests, including CLI-style tests (cmd_signer), file_stream tests, version tests.
• tests/CMakeLists.txt – build and link the test binaries.
• Documentation:
• docs/usage.md, docs/c_api.md – guides on using the public API.
Key points from the README
• The library is intended to be added via CMake FetchContent to any CMake-based project.
• It automatically selects the right c2pa-rs dynamic library per platform or allows building your own.
• You link your executable against the c2pa_cpp target to get the C++ APIs.
Main components
a. Application layer (consumer)
– Your C++ application or CLI tool (examples/demo.cpp, your “myapp”)
– Links to the c2pa_cpp CMake target
b. c2pa_cpp library
– Public API (include/c2pa.hpp)
– Implementation (src/c2pa.cpp)
– Build system (CMakeLists.txt, Makefile)
c. Underlying c2pa-rs dynamic libraries (Rust modules)
– Crypto & manifest processing engines
– Platform-specific shared libs (.so/.dylib/.dll)
d. Media files & Manifests
– Supported image/video formats (PNG, JPEG, etc.)
– In-file C2PA manifests (embedded metadata)
e. Test harness & examples
– Unit tests
– CLI-style tests (cmd_signer)
– Example apps demonstrating read/write flows
Relationships and data flow
• The application invokes c2pa_cpp APIs →
• c2pa_cpp forwards calls via FFI into the Rust dynamic libraries →
• Rust libs parse or serialize C2PA manifests in media files →
• Results (validation status, manifest JSON, modified files) are returned back up through c2pa_cpp →
• Application consumes or displays results.
Architectural patterns & design principles
• Wrapper/Facade: c2pa_cpp hides FFI complexity behind a clean C++ API.
• Modular layering: separation of build system, public API, implementation, and external dependencies.
• Test-driven design: comprehensive unit & integration tests exercising both API and CLI behaviors.