C2PA manifest embedding for structured text formats
Implements the Structured Text Embedding section of the C2PA Technical Specification, which defines how to associate a C2PA Manifest Store with source code, configuration files, markup, and other text formats that support comment syntax or front matter conventions.
The manifest block uses fixed ASCII armour-style delimiters modelled on RFC 4880:
-----BEGIN C2PA MANIFEST----- <reference> -----END C2PA MANIFEST-----
[dependencies]
c2pa-structured-text = "0.1"use c2pa_structured_text::{embed_manifest, ManifestRef};
let text = "print('hello')\n";
let signed = embed_manifest(
text,
ManifestRef::Url("https://example.com/manifests/abc.c2pa"),
"#", // comment prefix
None, // no comment suffix
);
// Result:
// # -----BEGIN C2PA MANIFEST----- https://example.com/manifests/abc.c2pa -----END C2PA MANIFEST-----
// print('hello')use c2pa_structured_text::extract_manifest;
let text = "# -----BEGIN C2PA MANIFEST----- https://example.com/m.c2pa -----END C2PA MANIFEST-----\nprint('hello')\n";
let result = extract_manifest(text).unwrap();
assert_eq!(result.reference, "https://example.com/m.c2pa");Any text format with a comment syntax or front matter convention:
| Comment Style | Formats | Example |
|---|---|---|
# |
Python, Ruby, Shell, YAML, TOML | # -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- |
// |
JavaScript, TypeScript, Go, Rust, C++ | // -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- |
-- |
SQL, Lua, Haskell | -- -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- |
/* */ |
CSS, C, Java | /* -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- */ |
<!-- --> |
HTML, XML, Markdown | <!-- -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- --> |
NOTE |
WebVTT | NOTE -----BEGIN C2PA MANIFEST----- ... -----END C2PA MANIFEST----- |
| Front matter | Markdown (YAML), TOML | Multi-line form between front matter delimiters |
| Crate | Description |
|---|---|
| c2pa-text-binding | Soft binding and content fingerprinting for text assets |
| c2pa-text | Unstructured text embedding via Unicode Variation Selectors |
| c2pa-rs | Official C2PA SDK |
Licensed under either of Apache License, Version 2.0 or MIT License at your option.
Built by WritersLogic