Expand description
This library supports reading, creating and embedding C2PA data with a variety of asset types.
We have a new experimental Builder/Reader API that will eventually replace
the existing methods of reading and writing C2PA data.
The new API focuses on stream support and can do more with fewer methods.
It will be supported in all language bindings and build environments.
To try these out, you need to enable the unstable_api
feature.
To read with file based methods, you must add the file_io
dependency to your Cargo.toml.
For example:
c2pa = {version="0.32.0", features=["file_io"]}
§Example: Reading a ManifestStore
use c2pa::{assertions::Actions, Reader};
let stream = std::fs::File::open("tests/fixtures/C.jpg")?;
let reader = Reader::from_stream("image/jpeg", stream)?;
println!("{}", reader.json());
if let Some(manifest) = reader.active_manifest() {
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, Builder, SigningAlg};
use serde::Serialize;
use tempfile::tempdir;
#[derive(Serialize)]
struct Test {
my_tag: usize,
}
let mut builder = Builder::from_json(r#"{"title": "Test"}"#)?;
builder.add_assertion("org.contentauth.test", &Test { my_tag: 42 })?;
// Create a ps256 signer using certs and key files
let signer = create_signer::from_files(
"tests/fixtures/certs/ps256.pub",
"tests/fixtures/certs/ps256.pem",
SigningAlg::Ps256,
None,
)?;
// embed a manifest using the signer
std::fs::remove_file("../target/tmp/lib_sign.jpg"); // ensure the file does not exist
builder.sign_file(
&*signer,
"tests/fixtures/C.jpg",
"../target/tmp/lib_sign.jpg",
)?;
Modules§
- Assertion helpers to build, validate, and parse assertions.
- Provides access to COSE signature generation.
- create_signer
openssl_sign
Thecreate_signer
module provides a way to obtain aSigner
instance for each signing format supported by this crate. - Implements validation status for specific parts of a manifest.
Structs§
- Builder
unstable_api
A Builder is used to add a signed manifest to an asset. - Defines a signer that uses a callback to sign data.
- Description of the claim generator, or the software used in generating the claim.
- DefaultOptions
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
- ManifestDefinition
unstable_api
A Manifest Definition This is used to define a manifest and is used to build a ManifestStore A Manifest is a collection of ingredients and assertions It is used to define a claim that can be signed and embedded into a file - ManifestStore
v1_api
A Container for a set of Manifests and a ValidationStatus list - ManifestStoreReport
v1_api
Low level JSON based representation of Manifest Store - used for debugging - Reader
unstable_api
A reader for the manifest store. - A reference to a resource to be used in JSON serialization.
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§
- The
AsyncSigner
trait generates a cryptographic signature over a byte array. - CAIRead
v1_api
- CAIReadWrite
v1_api
- IngredientOptions
file_io
This defines optional operations when creatingIngredient
structs from files. - The
Signer
trait generates a cryptographic signature over a byte array.
Functions§
- Return a MIME type given a file path.
Type Aliases§
- Defines a callback function interface for a
CallbackSigner
. - A specialized
Result
type for C2PA toolkit operations.