c2pa 0.3.0

Rust SDK for C2PA (Coalition for Content Provenance and Authenticity) implementors
Documentation

This library supports reading, creating and embedding C2PA data with JPEG and PNG images.

Example: Reading a ManifestStore

# use c2pa::Result;
use c2pa::{assertions::Actions, ManifestStore};

# fn main() -> Result<()> {
let manifest_store = ManifestStore::from_file("tests/fixtures/C.jpg")?;
println!("{}", manifest_store);

if let Some(manifest) = manifest_store.get_active() {
let actions: Actions = manifest.find_assertion(Actions::LABEL)?;
for action in actions.actions {
println!("{}\n", action.action());
}
}
# Ok(())
# }

Example: Adding a Manifest to a file

# use c2pa::Result;
use c2pa::{
assertions::User,
get_temp_signer,
Manifest
};

use std::path::PathBuf;
use tempfile::tempdir;

# fn main() -> Result<()> {
let mut manifest = Manifest::new("my_app".to_owned());
manifest.add_assertion(&User::new("org.contentauth.mylabel", r#"{"my_tag":"Anything I want"}"#))?;

let source = PathBuf::from("tests/fixtures/C.jpg");
let dir = tempdir()?;
let dest = dir.path().join("test_file.jpg");

let (signer, _) = get_temp_signer(&dir.path());
manifest.embed(&source, &dest, &signer)?;
# Ok(())
# }