External Manifest Stores

The ClaimGenerator and ClaimValidator in libc2pa provide several methods to work with external manifest store files. These deliver the ability to create and validate a manifest store that can be stored alongside the media file, rather than embedded within the file.

NOTE: These methods were introduced in v3.5.0 of libc2pa.

Create an External Manifest Store With the ClaimGenerator

#include "C2PA/C2PAFactory.hpp"

void main() {
	// Setup claim generation options.
  auto cg_opt = c2pa::C2PAFactory::new_generation_options();
  // This must be set when creating an external manifest store. The
  // format of the hard binding assertion is different for external
  // vs. embedded.
  cg_opt->force_external_manifest_store = true;
  
  // Create a ClaimGeneratorBuilder.
  auto builder = c2pa::C2PAFactory::new_claim_generator_builder(cg_opt);
  
  // Call methods on it.
  builder
    // Provide claim information.
    ->set_media_title("image.jpg")
    ->set_instance_id("3cc0ae0a-96df-4097-8d5f-ebc85dd1d996")
    
    // Provide assertions.
    ->add_assertion("metadata", exif_json)
    ->add_assertion("thumbnail", thumbnail_json)
    
    // Provide signature information
    ->set_algorithm(common::SignatureAlgorithm::ES256)
    ->set_certificate_chain({certificate_asset})
    
    // Provide media data
    ->set_media_data(input_jpeg_asset);

  // Create the ClaimGenerator.
  auto cg = builder->build();
    
  // Provide a timestamp
  cg->set_tsa_response(
    post_tsa_request(cg->get_tsa_request())
  );
    
  // Perform the signature operation
  auto manifest_store_asset = cg->create_manifest_store(
    sign_with_rsa_pss(cg->get_to_be_signed())
  );
}

force_external_manifest_store

This should always be set to true on the GenerationOptions object when the goal is to generate an external manifest store via the create_manifest_store() method.

  • bool - Set to true for an external manifest store.
cg_opt->force_external_manifest_store = true;

create_manifest_store()

This is analogous to the sign_media() method. It creates the new C2PA Manifest Store (with all Manifests, Claims, Signatures, etc.) and returns that structure as an Asset object.

  • std::vector<uint8_t> signature - The signature digest produced when signing the TBS structure.
auto manifest_store_asset = cg->create_manifest_store(signature_buffer);

Validate an External Manifest Store With the ClaimValidator

The validation works exactly as described in Validation except that the manifest store data must be provided in addition to the media data.

validate_external_manifest()

This returns a ValidationResult structure containing the results of the validation (see ValidationResult structure).

  • c2pa::ReadOnlyAssetPtr media - An Asset object containing the raw data of the media file to validate.
  • c2pa::ReadOnlyAssetPtr manifest - An Asset object containing the raw data of the manifest store.
auto validation_result = cv->validate_external_manifest(
  jpeg_asset,
  manifest_store_asset);

Manifest Store Utility Functions in the ManifestManipulator

Some workflows need to do very specific operations with manifest stores. These functions provide that functionality.

get_manifest_store()

Extracts an embedded manifest store from a media file and returns the structure as an Asset object.

  • c2pa::ReadOnlyAssetPtr asset - An Asset object containing the raw data of the media file to analyze.
auto manifest_store_asset =
  c2pa::C2PAFactory::new_manifest_manipulator()
  ->get_manifest_store(input_jpeg_asset);

embed_manifest_store()

Embeds the provided manifest store into a media file.

Returns the resulting media file as an Asset object.

  • c2pa::ReadWriteAssetPtr asset - An Asset object containing the media file to embed into.
  • c2pa::ReadOnlyAssetPtr manifest_store - An Asset object containing the raw manifest store data to embed into the media file.
auto output_jpeg_asset =
  c2pa::C2PAFactory::new_manifest_manipulator()
  ->insert_manifest_store(input_jpeg_asset, manifest_store_asset);

remove_manifest_store()

Removes an embedded manifest store from a media file.

Returns the resulting media file as an Asset object.

  • c2pa::ReadWriteAssetPtr asset - An Asset object containing the media file to remove from.
auto output_jpeg_asset =
  c2pa::C2PAFactory::new_manifest_manipulator()
  ->remove_manifest_store(input_jpeg_asset);