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 c2pa::{
assertions::User,
create_signer,
Manifest,
SigningAlg,
};
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 = 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.
file_io
Provides access to COSE signature generation.
file_io
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
file_io
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
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
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
async_signer
The AsyncSigner
trait generates a cryptographic signature over a byte array.
file_io
This defines optional operations when creating Ingredient
structs from files.
async_signer
The Signer
trait generates a cryptographic signature over a byte array.
Type Definitions
A specialized Result
type for C2PA toolkit operations.