Crate c2pa

source ·
Expand description

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

To read or write a manifest file, you must add the file_io dependency to your Cargo.toml. EXCEPTION: If you are building for WASM, do not add this dependency. For example:

c2pa = {version="0.11.0", features=["file_io"]}

§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 std::path::PathBuf;

use c2pa::{create_signer, Manifest, SigningAlg};
use serde::Serialize;
use tempfile::tempdir;

#[derive(Serialize)]
struct Test {
    my_tag: usize,
}

let mut manifest = Manifest::new("my_app".to_owned());
manifest.add_labeled_assertion("org.contentauth.test", &Test { my_tag: 42 })?;

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 = create_signer::from_files(signcert_path, pkey_path, SigningAlg::Ps256, None)?;

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

Modules§

  • Assertion helpers to build, validate, and parse assertions.
  • Provides access to COSE signature generation.
  • create_signeropenssl_sign
    The create_signer module provides a way to obtain a Signer instance for each signing format supported by this crate.
  • Implements validation status for specific parts of a manifest.

Structs§

  • Internal Assertion structure
  • Description of the claim generator, or the software used in generating the claim.
  • DefaultOptions returns None for Title and Hash and generates thumbnail for supported thumbnails
  • An Ingredient is any external asset that has been used in the creation of an image.
  • 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
  • A reference to a resource to be used in JSON serialization.
  • Resource store to contain binary objects referenced from JSON serializable structures
  • This error is thrown when converting from a string to SigningAlg if the algorithm string is unrecognized.

Enums§

  • Error enumerates errors returned by most C2PA toolkit operations.
  • Assertions in C2PA can be stored in several formats
  • Describes the digital signature algorithms allowed by the C2PA spec.

Constants§

  • The internal name of the C2PA SDK
  • The version of this C2PA SDK

Traits§

Functions§

Type Aliases§

  • A specialized Result type for C2PA toolkit operations.