c2pa-c
C++ API for c2pa-c library
Loading...
Searching...
No Matches
c2pa::Builder Class Reference

Builder class for creating a manifest. More...

#include <c2pa.hpp>

Public Member Functions

 Builder (const std::string &manifest_json)
 Create a Builder from a manifest JSON string.
 
 ~Builder ()
 
void set_no_embed ()
 Set the no embed flag.
 
void set_remote_url (const string &remote_url)
 Set the remote URL.
 
void set_base_path (const string &base_path)
 Set the base path for loading resources from files. Loads from memory if this is not set.
 
void add_resource (const string &uri, istream &source)
 Add a resource to the builder.
 
void add_resource (const string &uri, const std::filesystem::path &source_path)
 Add a resource to the builder.
 
void add_ingredient (const string &ingredient_json, const string &format, istream &source)
 Add an ingredient to the builder.
 
void add_ingredient (const string &ingredient_json, const std::filesystem::path &source_path)
 Add an ingredient to the builder.
 
void add_action (const string &action_json)
 Add an action to the manifest the Builder is constructing.
 
std::vector< unsigned char > sign (const string &format, istream &source, ostream &dest, Signer &signer)
 Sign an input stream and write the signed data to an output stream.
 
std::vector< unsigned char > sign (const string &format, istream &source, iostream &dest, Signer &signer)
 Sign an input stream and write the signed data to an output stream.
 
std::vector< unsigned char > sign (const path &source_path, const path &dest_path, Signer &signer)
 Sign a file and write the signed data to an output file.
 
void to_archive (ostream &dest)
 Write the builder to an archive stream.
 
void to_archive (const path &dest_path)
 Write the builder to an archive file.
 
std::vector< unsigned char > data_hashed_placeholder (uintptr_t reserved_size, const string &format)
 Create a hashed placeholder from the builder.
 
std::vector< unsigned char > sign_data_hashed_embeddable (Signer &signer, const string &data_hash, const string &format, istream *asset=nullptr)
 Sign a Builder using the specified signer and data hash.
 

Static Public Member Functions

static Builder from_archive (istream &archive)
 Create a Builder from an archive.
 
static Builder from_archive (const std::filesystem::path &archive_path)
 Create a Builder from an archive.
 
static std::vector< unsigned char > format_embeddable (const string &format, std::vector< unsigned char > &data)
 convert an unformatted manifest data to an embeddable format.
 
static std::vector< std::string > supported_mime_types ()
 Returns a vector of mime types that the SDK is able to sign.
 

Detailed Description

Builder class for creating a manifest.

This class is used to create a manifest from a json string and add resources and ingredients to the manifest.

Constructor & Destructor Documentation

◆ Builder()

c2pa::Builder::Builder ( const std::string &  manifest_json)

Create a Builder from a manifest JSON string.

Parameters
manifest_jsonThe manifest JSON string.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ ~Builder()

c2pa::Builder::~Builder ( )

Member Function Documentation

◆ add_action()

void c2pa::Builder::add_action ( const string &  action_json)

Add an action to the manifest the Builder is constructing.

Parameters
action_jsonJSON string containing the action data.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ add_ingredient() [1/2]

void c2pa::Builder::add_ingredient ( const string &  ingredient_json,
const std::filesystem::path &  source_path 
)

Add an ingredient to the builder.

Parameters
ingredient_jsonAny fields of the ingredient you want to define.
source_pathThe path to the ingredient file.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ add_ingredient() [2/2]

void c2pa::Builder::add_ingredient ( const string &  ingredient_json,
const string &  format,
istream &  source 
)

Add an ingredient to the builder.

Parameters
ingredient_jsonAny fields of the ingredient you want to define.
formatThe format of the ingredient file.
sourceThe input stream to read the ingredient from.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2pa library.

◆ add_resource() [1/2]

void c2pa::Builder::add_resource ( const string &  uri,
const std::filesystem::path &  source_path 
)

Add a resource to the builder.

Parameters
uriThe uri of the resource.
source_pathThe path to the resource file.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ add_resource() [2/2]

void c2pa::Builder::add_resource ( const string &  uri,
istream &  source 
)

Add a resource to the builder.

Parameters
uriThe uri of the resource.
sourceThe input stream to read the resource from.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ data_hashed_placeholder()

std::vector< unsigned char > c2pa::Builder::data_hashed_placeholder ( uintptr_t  reserved_size,
const string &  format 
)

Create a hashed placeholder from the builder.

Parameters
reserved_sizeThe size required for a signature from the intended signer.
formatThe format of the mime type or extension of the asset.
Returns
A vector containing the hashed placeholder.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ format_embeddable()

static std::vector< unsigned char > c2pa::Builder::format_embeddable ( const string &  format,
std::vector< unsigned char > &  data 
)
static

convert an unformatted manifest data to an embeddable format.

Parameters
formatThe format for embedding into.
dataAn unformatted manifest data block from sign_data_hashed_embeddable using "c2pa" format.
Returns
A formatted copy of the data.

◆ from_archive() [1/2]

static Builder c2pa::Builder::from_archive ( const std::filesystem::path &  archive_path)
static

Create a Builder from an archive.

Parameters
archive_paththe path to the archive file
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library

◆ from_archive() [2/2]

static Builder c2pa::Builder::from_archive ( istream &  archive)
static

Create a Builder from an archive.

Parameters
archiveThe input stream to read the archive from.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ set_base_path()

void c2pa::Builder::set_base_path ( const string &  base_path)

Set the base path for loading resources from files. Loads from memory if this is not set.

Parameters
base_pathThe base path to set.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
This method is planned to be deprecated in a future release. Usage should be limited and temporary. Use add_resource instead.

◆ set_no_embed()

void c2pa::Builder::set_no_embed ( )

Set the no embed flag.

◆ set_remote_url()

void c2pa::Builder::set_remote_url ( const string &  remote_url)

Set the remote URL.

Parameters
remote_urlThe remote URL to set.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ sign() [1/3]

std::vector< unsigned char > c2pa::Builder::sign ( const path source_path,
const path dest_path,
Signer signer 
)

Sign a file and write the signed data to an output file.

Parameters
source_pathThe path to the file to sign.
dest_pathThe path to write the signed file to.
signerA signer object to use when signing.
Returns
A vector containing the signed manifest bytes.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ sign() [2/3]

std::vector< unsigned char > c2pa::Builder::sign ( const string &  format,
istream &  source,
iostream &  dest,
Signer signer 
)

Sign an input stream and write the signed data to an output stream.

Parameters
formatThe format of the output stream.
sourceThe input stream to sign.
destThe in/output stream to write the signed data to.
signer
Returns
A vector containing the signed manifest bytes.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ sign() [3/3]

std::vector< unsigned char > c2pa::Builder::sign ( const string &  format,
istream &  source,
ostream &  dest,
Signer signer 
)

Sign an input stream and write the signed data to an output stream.

Parameters
formatThe format of the output stream.
sourceThe input stream to sign.
destThe output stream to write the signed data to.
signer
Returns
A vector containing the signed manifest bytes.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library
Deprecated:
Use sign(const string&, istream&, iostream&, Signer&)

◆ sign_data_hashed_embeddable()

std::vector< unsigned char > c2pa::Builder::sign_data_hashed_embeddable ( Signer signer,
const string &  data_hash,
const string &  format,
istream *  asset = nullptr 
)

Sign a Builder using the specified signer and data hash.

Parameters
signerThe signer to use for signing.
data_hashThe data hash ranges to sign. This must contain hashes unless and asset is provided.
formatThe mime format for embedding into. Use "c2pa" for an unformatted result.
assetAn optional asset to hash according to the data_hash information.
Returns
A vector containing the signed data.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ supported_mime_types()

static std::vector< std::string > c2pa::Builder::supported_mime_types ( )
static

Returns a vector of mime types that the SDK is able to sign.

◆ to_archive() [1/2]

void c2pa::Builder::to_archive ( const path dest_path)

Write the builder to an archive file.

Parameters
dest_pathThe path to write the archive file to.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

◆ to_archive() [2/2]

void c2pa::Builder::to_archive ( ostream &  dest)

Write the builder to an archive stream.

Parameters
destThe output stream to write the archive to.
Exceptions
C2pa::C2paExceptionfor errors encountered by the C2PA library.

The documentation for this class was generated from the following file: