Crate c2pa

source · []
Expand description

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

Example: Reading a ManifestStore

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

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());
    }
}

Example: Adding a Manifest to a file

use c2pa::{
    assertions::User,
    get_signer_from_files,
    Manifest
};

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

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");

// Create a ps256 signer using certs and key files
let signcert_path = "tests/fixtures/certs/ps256.pub";
let pkey_path = "tests/fixtures/certs/ps256.pem";
let signer = get_signer_from_files(signcert_path, pkey_path, "ps256", None)?;

// embed a manifest using the signer
manifest.embed(&source, &dest, &*signer)?;

Modules

Assertion helpers to build, validate, and parse assertions.

Implements validation status for specific parts of a manifest.

Structs

Internal Assertion structure

An Ingredient is any external asset that has been used in the creation of an image.

This defines optional actions when creating Ingredients from files.

A Manifest represents all the information in a c2pa manifest

A labeled container for an Assertion value in a Manifest

A Container for a set of Manifests and a ValidationStatus list

Low level JSON based representation of Manifest Store - used for debugging

Enums

Error enumerates errors returned by most C2PA toolkit operations.

Assertions in C2PA can be stored in several formats

Constants

The internal name of the C2PA SDK

The version of this C2PA SDK

Traits

The core required trait for all assertions.

Trait to handle default Cbor encoding/decoding of Assertions

Trait to handle default Json encoding/decoding of Assertions

Type Definitions

A specialized Result type for C2PA toolkit operations.