Thanks to visit codestin.com
Credit goes to docs.rs

Crate c2pa

Crate c2pa 

Source
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 openssl implementation for cryptography.
  • rust_native_crypto: Use Rust native cryptography.
  • add_thumbnails: Adds the image crate 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 schemars crate 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_signer module provides a way to obtain a Signer instance 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.
CallbackSigner
Defines a signer that uses a callback to sign data.
ClaimGeneratorInfo
Description of the claim generator, or the software used in generating the claim.
DefaultOptionsfile_io
DefaultOptions returns None for Title and Hash and generates thumbnail for supported thumbnails.
HashRange
Defines a hash range to be used with hash_stream_by_alg
HashedUri
A HashedUri provides a reference to content available within the same manifest store.
Ingredient
An Ingredient is any external asset that has been used in the creation of an asset.
Manifest
A Manifest represents all the information in a c2pa manifest
ManifestAssertion
A labeled container for an Assertion value in a Manifest
ManifestDefinition
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.
ResourceRef
A reference to a resource to be used in JSON serialization.
ResourceStore
Resource store to contain binary objects referenced from JSON serializable structures
SignatureInfo
Holds information about a signature
ValidationResults
A map of validation results for a manifest store.

Enums§

BuilderIntent
Represents the type of builder flow being used.
Error
Error enumerates errors returned by most C2PA toolkit operations.
ManifestAssertionKind
Assertions in C2PA can be stored in several formats
Relationship
The relationship of the ingredient to the current asset.
SigningAlg
Describes the digital signature algorithms allowed by the C2PA spec.
ValidationState
Indicates if the manifest store is valid and trusted.

Constants§

NAME
The internal name of the C2PA SDK
VERSION
The version of this C2PA SDK

Traits§

AsyncSigner
The AsyncSigner trait generates a cryptographic signature over a byte array.
IngredientOptionsfile_io
This defines optional operations when creating Ingredient structs from files.
ManifestPatchCallback
Signer
The Signer trait 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§

CallbackFunc
Defines a callback function interface for a CallbackSigner.
Result
A specialized Result type for C2PA toolkit operations.