Expand description
This library supports reading, creating, and embedding C2PA data for a variety of asset types.
Some functionality requires you to enable specific crate features, as noted in the documentation.
The library has a Builder/Reader API that focuses on simplicity and stream support.
§Examples
§Reading a manifest
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());
}
}§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,
}
#[cfg(feature = "file_io")]
{
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",
)?;
}§Features
You can enable any of the following features:
- openssl (enabled by default): Use the vendored
opensslimplementation for cryptography. - rust_native_crypto: Use Rust native cryptography.
- add_thumbnails: Adds the
imagecrate to enable auto-generated thumbnails, if possible and enabled in settings. - fetch_remote_manifests: Fetches remote manifests over the network when no embedded manifest is present and that option is enabled in settings.
- file_io: Enables APIs that use filesystem I/O.
- json_schema: Adds the
schemarscrate to derive JSON schemas for JSON-compatible structs. - pdf: Enables basic PDF read support.
Re-exports§
pub use assertions::DigitalSourceType;
Modules§
- assertions
- The assertions module contains the definitions for the assertions that are part of the C2PA specification. Assertion helpers to build, validate, and parse assertions.
- cose_
sign - The cose_sign module contains the definitions for the COSE signing algorithms. Provides access to COSE signature generation.
- create_
signer - The create_signer module contains the definitions for the signers that are part of the C2PA specification.
The
create_signermodule provides a way to obtain aSignerinstance for each signing format supported by this crate. - jumbf_
io - The jumbf_io module contains the definitions for the JUMBF data in assets.
- settings
- The settings module provides a way to configure the C2PA SDK.
- validation_
results - The validation_results module contains the definitions for the validation results that are part of the C2PA specification.
Structs§
- Builder
- Use a Builder to add a signed manifest to an asset.
- Callback
Signer - Defines a signer that uses a callback to sign data.
- Claim
Generator Info - Description of the claim generator, or the software used in generating the claim.
- Default
Options file_io - DefaultOptions returns None for Title and Hash and generates thumbnail for supported thumbnails.
- Hash
Range - Defines a hash range to be used with
hash_stream_by_alg - Hashed
Uri - A
HashedUriprovides a reference to content available within the same manifest store. - Ingredient
- An
Ingredientis any external asset that has been used in the creation of an asset. - Manifest
- A Manifest represents all the information in a c2pa manifest
- Manifest
Assertion - A labeled container for an Assertion value in a Manifest
- Manifest
Definition - Use a ManifestDefinition to define a manifest and to build a
ManifestStore. A manifest is a collection of ingredients and assertions used to define a claim that can be signed and embedded into a file. - Reader
- Use a Reader to read and validate a manifest store.
- Resource
Ref - A reference to a resource to be used in JSON serialization.
- Resource
Store - Resource store to contain binary objects referenced from JSON serializable structures
- Signature
Info - Holds information about a signature
- Validation
Results - A map of validation results for a manifest store.
Enums§
- Builder
Intent - Represents the type of builder flow being used.
- Error
Errorenumerates errors returned by most C2PA toolkit operations.- Manifest
Assertion Kind - Assertions in C2PA can be stored in several formats
- Relationship
- The relationship of the ingredient to the current asset.
- Signing
Alg - Describes the digital signature algorithms allowed by the C2PA spec.
- Validation
State - Indicates if the manifest store is valid and trusted.
Constants§
Traits§
- Async
Signer - The
AsyncSignertrait generates a cryptographic signature over a byte array. - Ingredient
Options file_io - This defines optional operations when creating
Ingredientstructs from files. - Manifest
Patch Callback - Signer
- The
Signertrait generates a cryptographic signature over a byte array.
Functions§
- format_
from_ path - Return a MIME type given a file path.
- hash_
stream_ by_ alg
Type Aliases§
- Callback
Func - Defines a callback function interface for a
CallbackSigner. - Result
- A specialized
Resulttype for C2PA toolkit operations.