Skip to main content

c2pa_structured_text/
lib.rs

1// Copyright 2026 WritersLogic. All rights reserved.
2// Licensed under the Apache License, Version 2.0 or the MIT license,
3// at your option.
4
5//! C2PA manifest embedding, hard binding, and validation for structured text.
6//!
7//! Implements the *Embedding Manifests into Structured Text* section of the
8//! C2PA Technical Specification, which associates a C2PA Manifest Store with
9//! source code, configuration files, markup, and other text formats that
10//! support comment syntax or front matter conventions.
11//!
12//! The manifest block uses fixed ASCII armour-style delimiters:
13//! `-----BEGIN C2PA MANIFEST-----` and `-----END C2PA MANIFEST-----`.
14//!
15//! # Scope
16//!
17//! This crate owns three things:
18//!
19//! - **Embed** ([`embed_manifest`], [`embed_manifest_at_end`],
20//!   [`embed_front_matter`]) a reference or an inline manifest as a comment or
21//!   front matter block.
22//! - **Extract** ([`extract_manifest`], [`classify_reference`]) the block and
23//!   resolve its reference.
24//! - The **hard binding** ([`hardbinding`]): the exact `c2pa.hash.data`
25//!   coverage over the normalized-free raw byte stream, with the manifest block
26//!   excluded, plus compute and verify.
27//!
28//! Signature verification, certificate trust, and assertion validation are
29//! **not** implemented here; the [`bridge`] (feature `c2pa`) delegates them to
30//! `c2pa-rs`.
31//!
32//! # Features
33//!
34//! - `hard-binding` — concrete SHA2-256/384/512 [`hardbinding::compute_data_hash`]
35//!   and [`hardbinding::verify_data_hash`] (pulls `sha2`). The exclusion-range
36//!   and covered-byte primitives ([`hardbinding::manifest_exclusion`],
37//!   [`hardbinding::hashed_bytes`]) are always available and dependency-free.
38//! - `c2pa` — the [`bridge`] to `c2pa-rs` for signature/trust/assertion validation.
39//! - `remote` — HTTP(S) resolution of URL references in the bridge (pulls `ureq`).
40//! - `wasm` — JS/WASM bindings for the npm package (pulls `wasm-bindgen`).
41//! - `python` — Python bindings for the PyPI wheel (pulls `pyo3`, built with maturin).
42//!
43//! No feature is enabled by default; the core embed/extract/binding-range API
44//! has no dependencies.
45
46mod codec;
47mod embed;
48mod error;
49mod extract;
50pub mod hardbinding;
51
52#[cfg(feature = "c2pa")]
53pub mod bridge;
54
55#[cfg(feature = "wasm")]
56mod wasm;
57
58#[cfg(feature = "python")]
59mod python;
60
61pub use embed::{embed_front_matter, embed_manifest, embed_manifest_at_end, ManifestRef};
62pub use error::Error;
63pub use extract::{classify_reference, extract_manifest, ExtractionResult, Reference};