# contentauth/c2patool architecture

> Architecture diagram of the GitHub repository contentauth/c2patool, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/contentauth/c2patool
- Repository: https://github.com/contentauth/c2patool

## Overview

##### Project type and purpose
- Type: A standalone command-line tool, written in Rust, for creating, signing, inspecting, and validating C2PA manifests embedded in media assets.
- Purpose: Consume media+manifest inputs, apply cryptographic operations, validate or generate manifest structures according to the C2PA spec, and output results to disk or stdout.

##### File structure
- Top-level crates and configs:
– Cargo.toml / Cargo.lock – Rust package manifest and versions
– Makefile – build/test automation
– . github/workflows – CI pipelines for lint/test/release
– deny.toml, rustfmt.toml – code style and security linting
- Source layout (src/):
– main.rs – CLI entrypoint, argument parsing, subcommand dispatch
– callback_signer.rs – support for interactive or external callbacks during signing
– info.rs – modules to extract and display manifest/media info
– signer.rs – core signing logic (PS256, ES256, etc.)
– tree.rs – manifest tree construction and serialization
- Support dirs:
– schemas/ – JSON schema definitions for validation of manifest and ingredient payloads
– sample/ – sample keys, certs, configs for users and tests
– tests/ – unit and integration tests with fixtures

##### README for additional insights
- High-level description points to C2PA spec compliance and CLI usage.

a. Main components:
1. CLI Frontend (main.rs + argument parser)
2. Command Dispatcher (subcommands: sign, verify, dump-info, tree, etc.)
3. Core Library Modules:
- Signer Module (signer.rs)
- Tree Builder (tree.rs)
- Info/Inspector (info.rs)
- Callback Handler (callback_signer.rs)
4. JSON Schema Validator (schemas/)
5. Crypto Subsystem (Rust’s crypto crates, e.g. ring, openssl wrappers)
6. File I/O Layer (read/write files, PEM, media assets)
7. Configuration & Samples (sample/)
8. Test Harness & Fixtures (tests/)
9. CI/CD & Build System (Makefile, GitHub Actions)
b. Relationships & data flows:
– User invokes `c2patool` CLI → Frontend parses args → Dispatcher
– Dispatcher routes to module (e.g., Signer) → loads manifest JSON → validates with JSON Schema → signs with Crypto Subsystem → writes updated manifest into media file via File I/O
– Info module reads media+manifest → extracts metadata → outputs to console
– Callback module may call out to user-provided functions or external processes during signing
– Tests drive modules with sample fixtures to verify correct behavior
c. Architectural patterns & design principles:
- Modular separation – thin CLI wrapper around core library modules
- Single-Responsibility – each module handles one aspect (signing, tree building, info)
- Extensibility – JSON schema folder allows new manifest types or ingredient definitions
- Configurable crypto – sample configs and deny.toml enforce policy
d. Key technologies/frameworks:
– Rust & Cargo package management
– Serde + JSON Schema validation crates
– Cryptography crates (ring/openssl)
– GitHub Actions (CI)
– Makefile for local cross-platform builds

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entities
    User["User"]:::external

    %% CLI Layer
    subgraph "CLI Layer"
        CLI["CLI Frontend\n(argument parser)"]:::cli
        Dispatcher["Command Dispatcher"]:::cli
    end

    %% Core Library
    subgraph "Core Library"
        Signer["Signer Module"]:::core
        Tree["Tree Builder"]:::core
        Info["Info/Inspector Module"]:::core
        Callback["Callback Handler"]:::core
    end

    %% Support Components
    subgraph "Support & Infra"
        Schema["JSON Schema Validator"]:::external
        Crypto["Crypto Subsystem"]:::external
        FileIO["File I/O Layer"]:::external
        Samples["Configuration & Samples"]:::external
        Tests["Test Harness & Fixtures"]:::external
        CI["CI/CD & Build System"]:::external
    end

    %% Data Flows
    User -->|"Invokes CLI"| CLI
    CLI -->|"Parses args"| Dispatcher
    Dispatcher -->|"routes to"| Signer
    Dispatcher -->|"routes to"| Tree
    Dispatcher -->|"routes to"| Info
    Dispatcher -->|"routes to"| Callback

    Signer -->|" validates with "| Schema
    Signer -->|" uses "| Crypto
    Signer -->|" writes via "| FileIO

    Tree -->|" validates with "| Schema
    Tree -->|" writes via "| FileIO

    Info -->|" reads via "| FileIO

    Callback -->|" interacts via "| FileIO

    Tests -->|"drives modules"| Signer
    Tests -->|"drives modules"| Tree
    Tests -->|"drives modules"| Info
    Tests -->|"drives modules"| Callback

    CI -->|"builds/tests"| CLI
    CI -->|"builds/tests"| Signer
    CI -->|"builds/tests"| Tree
    CI -->|"builds/tests"| Info
    CI -->|"builds/tests"| Callback
    CI -->|"runs tests on"| Tests

    %% Click Events
    click CLI "https://github.com/contentauth/c2patool/blob/main/src/main.rs"
    click Dispatcher "https://github.com/contentauth/c2patool/blob/main/src/main.rs"
    click Signer "https://github.com/contentauth/c2patool/blob/main/src/signer.rs"
    click Tree "https://github.com/contentauth/c2patool/blob/main/src/tree.rs"
    click Info "https://github.com/contentauth/c2patool/blob/main/src/info.rs"
    click Callback "https://github.com/contentauth/c2patool/blob/main/src/callback_signer.rs"
    click Schema "https://github.com/contentauth/c2patool/tree/main/schemas/"
    click Crypto "https://github.com/contentauth/c2patool/blob/main/src/signer.rs"
    click FileIO "https://github.com/contentauth/c2patool/blob/main/src/main.rs"
    click Samples "https://github.com/contentauth/c2patool/tree/main/sample/"
    click Tests "https://github.com/contentauth/c2patool/tree/main/tests/"
    click CI "https://github.com/contentauth/c2patool/tree/main/.github/workflows/"

    %% Styles
    classDef cli fill:#D0E8FF,stroke:#0366D6,stroke-width:2px;
    classDef core fill:#E0F8E0,stroke:#28A745,stroke-width:2px;
    classDef external fill:#F0F0F0,stroke:#6A737D,stroke-width:2px;
```
