c2pa_vtt/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 and hard binding for WebVTT subtitle and caption
6//! files.
7//!
8//! WebVTT is a structured text format, so a C2PA Manifest Store is associated
9//! with it using the fixed ASCII armour delimiters
10//! (`-----BEGIN C2PA MANIFEST-----` / `-----END C2PA MANIFEST-----`) inside a
11//! single-line `NOTE` comment placed immediately after the `WEBVTT` signature,
12//! as specified by the C2PA structured text embedding section. Placement after
13//! the signature (rather than at the start of the file) is what makes this
14//! WebVTT-specific: the `WEBVTT` line is a reserved header that must come first.
15//!
16//! ```text
17//! WEBVTT
18//!
19//! NOTE -----BEGIN C2PA MANIFEST----- https://example.com/m.c2pa -----END C2PA MANIFEST-----
20//!
21//! 00:00:00.000 --> 00:00:05.000
22//! Hello world
23//! ```
24//!
25//! # Scope relative to `c2pa-structured-text`
26//!
27//! `c2pa-structured-text` implements the general structured text embedding
28//! method and lists WebVTT as one comment style. This crate is the **canonical
29//! WebVTT implementation**: the general method's "prepend a comment line" rule
30//! would place the block before the `WEBVTT` signature and produce an invalid
31//! file, and the hard binding needs WebVTT-aware placement. `c2pa-structured-text`
32//! documents the WebVTT delimiter but defers correct placement and hard binding
33//! here.
34//!
35//! # Hard binding
36//!
37//! See [`binding`] for the byte-exact `c2pa.hash.data` data hash and the single
38//! exclusion range covering the manifest block.
39//!
40//! # Validation
41//!
42//! See [`bridge`] for extracting the manifest store and delegating
43//! signature/trust/assertion validation to the official C2PA SDK.
44//!
45//! # Features
46//!
47//! - `hash` (default): `sha2`-backed [`binding::compute_data_hash`] /
48//! [`binding::verify_data_hash`]. Disable with `default-features = false` for
49//! a zero-dependency embed/extract build.
50//! - `c2pa` (off by default): the [`bridge::validate`] delegation to c2pa-rs.
51
52pub mod binding;
53pub mod bridge;
54mod embed;
55mod error;
56mod extract;
57
58#[cfg(all(feature = "python", not(target_arch = "wasm32")))]
59mod python;
60
61#[cfg(target_arch = "wasm32")]
62mod wasm;
63
64pub use binding::{data_hash_exclusion, Exclusion, HashAlg};
65pub use bridge::{extract_manifest_source, ManifestSource};
66pub use embed::{embed_manifest, remove_manifest, ManifestRef};
67pub use error::Error;
68pub use extract::{extract_manifest, ExtractionResult};
69
70#[cfg(feature = "hash")]
71pub use binding::{compute_data_hash, verify_data_hash};