c2pa_ml/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 for AI/ML model container formats.
6//!
7//! A C2PA Manifest Store is associated with a model by writing it into the
8//! format's own metadata slot, so the model stays loadable by its usual
9//! runtime:
10//!
11//! - **GGUF** (llama.cpp) — a `c2pa.manifest` key/value metadata entry
12//! ([`gguf`]).
13//! - **SafeTensors** — a `c2pa.manifest` entry in the JSON header's
14//! `__metadata__` ([`safetensors`]).
15//! - **ONNX** — a `c2pa.manifest` entry in the protobuf `metadata_props`
16//! ([`onnx`]).
17//!
18//! A remote (or side-car) manifest can instead be referenced by URI under
19//! `c2pa.manifest.uri`, or both an embedded store and a URI can be written
20//! together (see [`ManifestSource`]).
21//!
22//! The top-level functions auto-detect the format:
23//!
24//! ```
25//! use c2pa_ml::{embed_manifest, read_manifest, ManifestSource};
26//! # fn demo(model: &[u8], store: Vec<u8>) -> Result<(), c2pa_ml::Error> {
27//! let signed = embed_manifest(model, &ManifestSource::embedded(store))?;
28//! let manifest = read_manifest(&signed)?;
29//! # let _ = manifest;
30//! # Ok(())
31//! # }
32//! ```
33//!
34//! # Asset type
35//!
36//! The C2PA core specification defines no dedicated embedding method for model
37//! containers; a manifest embedded in a model declares what the asset is with
38//! the asset type assertion. [`Format::model_type`] and [`asset_type::ModelType`]
39//! provide the canonical `c2pa.types.model.*` strings for that assertion.
40//!
41//! # Scope
42//!
43//! This crate implements embedding and extraction only. Manifest construction,
44//! signing, and content (hard/soft) binding are out of scope; use the
45//! [official C2PA SDK](https://crates.io/crates/c2pa) to build and sign
46//! manifests. The `c2pa.hash.data` assertion should exclude the metadata region
47//! carrying the Manifest Store.
48//!
49//! Zero dependencies on native targets; the WebAssembly/npm build uses only
50//! `wasm-bindgen`.
51
52mod base64;
53mod json;
54
55pub mod asset_type;
56pub mod gguf;
57pub mod onnx;
58pub mod safetensors;
59
60mod error;
61mod format;
62mod manifest;
63
64#[cfg(target_arch = "wasm32")]
65mod wasm;
66
67#[cfg(feature = "python")]
68mod python;
69
70pub use asset_type::ModelType;
71pub use error::Error;
72pub use format::{
73 embed_manifest, embed_manifest_as, read_manifest, read_manifest_uri, remove_manifest, verify,
74 Format, Report,
75};
76pub use manifest::ManifestSource;