|
c2pa-c
C++ API for c2pa-c library
|
Builder class for creating a manifest. More...
#include <c2pa.hpp>
Public Member Functions | |
| Builder (IContextProvider &context) | |
| Create a Builder from a context with an empty manifest. | |
| Builder (IContextProvider &context, const std::string &manifest_json) | |
| Create a Builder from a context and manifest JSON string. | |
| Builder (const std::string &manifest_json) | |
| Create a Builder from a manifest JSON string (will use global settings if any loaded). | |
| Builder (C2paBuilder *builder) | |
| Create a Builder from a raw C FFI builder. | |
| Builder (const Builder &)=delete | |
| Builder & | operator= (const Builder &)=delete |
| Builder (Builder &&other) noexcept | |
| Builder & | operator= (Builder &&other) noexcept |
| ~Builder () | |
| C2paBuilder * | c2pa_builder () const noexcept |
| Get the underlying C2paBuilder pointer. | |
| Builder & | with_definition (const std::string &manifest_json) |
| Set or update the manifest definition. | |
| void | set_no_embed () |
| Set the no-embed flag to prevent embedding the manifest in the asset. | |
| void | set_remote_url (const std::string &remote_url) |
| Set the remote URL. | |
| void | set_base_path (const std::string &base_path) |
| Set the base path for loading resources from files. | |
| void | add_resource (const std::string &uri, std::istream &source) |
| Add a resource to the builder from a stream. | |
| void | add_resource (const std::string &uri, const std::filesystem::path &source_path) |
| Add a resource to the builder from a file. | |
| void | add_ingredient (const std::string &ingredient_json, const std::string &format, std::istream &source) |
| Add an ingredient to the builder from a stream. | |
| void | add_ingredient (const std::string &ingredient_json, const std::filesystem::path &source_path) |
| Add an ingredient to the builder from a file. | |
| void | add_action (const std::string &action_json) |
| Add an action to the manifest. | |
| void | set_intent (C2paBuilderIntent intent, C2paDigitalSourceType digital_source_type=Empty) |
| Set the intent for this Builder, controlling what kind of manifest to create. | |
| std::vector< unsigned char > | sign (const std::string &format, std::istream &source, std::ostream &dest, Signer &signer) |
| Sign an input stream and write the signed data to an output stream. | |
| std::vector< unsigned char > | sign (const std::string &format, std::istream &source, std::iostream &dest, Signer &signer) |
| Sign an input stream and write the signed data to an I/O stream. | |
| std::vector< unsigned char > | sign (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, Signer &signer) |
| Sign a file and write the signed data to an output file. | |
| std::vector< unsigned char > | sign (const std::string &format, std::istream &source, std::iostream &dest) |
| Sign using the signer from the Builder's Context. | |
| std::vector< unsigned char > | sign (const std::filesystem::path &source_path, const std::filesystem::path &dest_path) |
| Sign a file using the signer from the Builder's Context. | |
| Builder & | with_archive (std::istream &archive) |
| Load an archive into this builder. | |
| void | to_archive (std::ostream &dest) |
| Write the builder to an archive stream. | |
| void | to_archive (const std::filesystem::path &dest_path) |
| Write the builder to an archive file. | |
| std::vector< unsigned char > | data_hashed_placeholder (uintptr_t reserved_size, const std::string &format) |
| Create a hashed placeholder from the builder. | |
| std::vector< unsigned char > | sign_data_hashed_embeddable (Signer &signer, const std::string &data_hash, const std::string &format, std::istream *asset=nullptr) |
| Sign a Builder using the specified signer and data hash. | |
| bool | needs_placeholder (const std::string &format) |
| Check if the given format requires a placeholder embedding step. | |
| std::vector< unsigned char > | placeholder (const std::string &format) |
| Create a composed placeholder manifest to embed in the asset. | |
| void | set_data_hash_exclusions (const std::vector< std::pair< uint64_t, uint64_t > > &exclusions) |
| Register the byte ranges where the placeholder was embedded (DataHash workflow). | |
| void | update_hash_from_stream (const std::string &format, std::istream &stream) |
| Compute and store the asset hash by reading a stream. | |
| std::vector< unsigned char > | sign_embeddable (const std::string &format) |
| Sign and return the final manifest bytes, ready for embedding. | |
Static Public Member Functions | |
| static Builder | from_archive (std::istream &archive) |
| Create a Builder from an archived Builder stream. | |
| static Builder | from_archive (const std::filesystem::path &archive_path) |
| Create a Builder from an archive. | |
| static std::vector< unsigned char > | format_embeddable (const std::string &format, std::vector< unsigned char > &data) |
| Convert unformatted manifest data to an embeddable format. | |
| static std::vector< std::string > | supported_mime_types () |
| Get a list of mime types that the Builder supports. | |
Builder class for creating a manifest.
This class is used to create a manifest from a json std::string and add resources and ingredients to the manifest.
|
explicit |
Create a Builder from a context with an empty manifest.
| context | Context provider; used at construction to configure settings. |
| C2paException | if context.is_valid() returns false, or for other errors encountered by the C2PA library. |
| c2pa::Builder::Builder | ( | IContextProvider & | context, |
| const std::string & | manifest_json | ||
| ) |
Create a Builder from a context and manifest JSON string.
| context | Context provider; used at construction to configure settings. |
| manifest_json | The manifest JSON string. |
| C2paException | if context.is_valid() returns false, or for other errors encountered by the C2PA library. |
| c2pa::Builder::Builder | ( | const std::string & | manifest_json | ) |
Create a Builder from a manifest JSON string (will use global settings if any loaded).
| manifest_json | The manifest JSON string. |
| C2paException | for errors encountered by the C2PA library. |
|
explicit |
Create a Builder from a raw C FFI builder.
| builder | Raw C2paBuilder pointer to wrap. |
| C2paException | if builder is nullptr. |
|
delete |
|
inlinenoexcept |
| c2pa::Builder::~Builder | ( | ) |
| void c2pa::Builder::add_action | ( | const std::string & | action_json | ) |
Add an action to the manifest.
| action_json | JSON string containing the action data. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::add_ingredient | ( | const std::string & | ingredient_json, |
| const std::filesystem::path & | source_path | ||
| ) |
Add an ingredient to the builder from a file.
| ingredient_json | Any fields of the ingredient you want to define. |
| source_path | The path to the ingredient file. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::add_ingredient | ( | const std::string & | ingredient_json, |
| const std::string & | format, | ||
| std::istream & | source | ||
| ) |
Add an ingredient to the builder from a stream.
| ingredient_json | Any fields of the ingredient you want to define. |
| format | The mime format of the ingredient. |
| source | The input stream to read the ingredient from. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::add_resource | ( | const std::string & | uri, |
| const std::filesystem::path & | source_path | ||
| ) |
Add a resource to the builder from a file.
| uri | The URI identifier for the resource. |
| source_path | The path to the resource file. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::add_resource | ( | const std::string & | uri, |
| std::istream & | source | ||
| ) |
Add a resource to the builder from a stream.
| uri | The URI identifier for the resource. |
| source | The input stream to read the resource from. |
| C2paException | for errors encountered by the C2PA library. |
|
noexcept |
Get the underlying C2paBuilder pointer.
| std::vector< unsigned char > c2pa::Builder::data_hashed_placeholder | ( | uintptr_t | reserved_size, |
| const std::string & | format | ||
| ) |
Create a hashed placeholder from the builder.
| reserved_size | The size required for a signature from the intended signer (in bytes). |
| format | The mime format or extension of the asset. |
| C2paException | for errors encountered by the C2PA library. |
|
static |
Convert unformatted manifest data to an embeddable format.
| format | The format for embedding. |
| data | Unformatted manifest data from sign_data_hashed_embeddable using "c2pa" format. |
|
static |
Create a Builder from an archive.
| archive_path | The path to the archive file. |
| C2paException | for errors encountered by the C2PA library. |
|
static |
Create a Builder from an archived Builder stream.
| archive | The input stream to read the archive from. |
| C2paException | for errors encountered by the C2PA library. |
| bool c2pa::Builder::needs_placeholder | ( | const std::string & | format | ) |
Check if the given format requires a placeholder embedding step.
Returns false for BoxHash-capable formats when prefer_box_hash is enabled in the context settings (no placeholder needed — hash covers the full asset). Always returns true for BMFF formats (MP4, etc.) regardless of settings.
| format | The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4"). |
| C2paException | on error. |
| std::vector< unsigned char > c2pa::Builder::placeholder | ( | const std::string & | format | ) |
Create a composed placeholder manifest to embed in the asset.
The signer (and its reserve size) are obtained from the Builder's Context. For BMFF assets, the placeholder includes a BmffHash assertion with default exclusions for the manifest UUID box. Returns empty bytes for formats that do not need a placeholder (BoxHash). The placeholder size is stored internally so sign_embeddable() returns bytes of exactly the same size, enabling in-place patching.
| format | The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4"). |
| C2paException | on error. |
| void c2pa::Builder::set_base_path | ( | const std::string & | base_path | ) |
Set the base path for loading resources from files.
When set, resources are loaded from files relative to this path. If not set, resources are loaded from memory.
| base_path | The base directory path. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::set_data_hash_exclusions | ( | const std::vector< std::pair< uint64_t, uint64_t > > & | exclusions | ) |
Register the byte ranges where the placeholder was embedded (DataHash workflow).
Call this after embedding the placeholder bytes into the asset and before update_hash_from_stream(). The exclusions replace the dummy ranges set by placeholder() so the asset hash covers all bytes except the manifest slot. Exclusions are (start, length) pairs in asset byte coordinates.
| exclusions | Vector of (start, length) pairs describing the embedded placeholder region. |
| C2paException | if no DataHash assertion exists or on other error. |
| void c2pa::Builder::set_intent | ( | C2paBuilderIntent | intent, |
| C2paDigitalSourceType | digital_source_type = Empty |
||
| ) |
Set the intent for this Builder, controlling what kind of manifest to create.
| intent | The intent type: Create, Edit, or Update. |
| digital_source_type | Required for Create intent. Describes how the asset was produced. Defaults to Empty. |
| C2paException | if the intent cannot be set. |
| void c2pa::Builder::set_no_embed | ( | ) |
Set the no-embed flag to prevent embedding the manifest in the asset.
When set, the manifest will be stored externally rather than embedded.
| void c2pa::Builder::set_remote_url | ( | const std::string & | remote_url | ) |
Set the remote URL.
| remote_url | The remote URL to set. |
| C2paException | for errors encountered by the C2PA library. |
| std::vector< unsigned char > c2pa::Builder::sign | ( | const std::filesystem::path & | source_path, |
| const std::filesystem::path & | dest_path | ||
| ) |
Sign a file using the signer from the Builder's Context.
The signer may have been set programmatically via ContextBuilder::with_signer(), or configured in settings JSON. If both programmatic and settings signers are present, the programmatic signer takes priority.
| source_path | The path to the file to sign. |
| dest_path | The path to write the signed file to. |
| C2paException | if the context has no signer or on other errors. |
| std::vector< unsigned char > c2pa::Builder::sign | ( | const std::filesystem::path & | source_path, |
| const std::filesystem::path & | dest_path, | ||
| Signer & | signer | ||
| ) |
Sign a file and write the signed data to an output file.
| source_path | The path to the file to sign. |
| dest_path | The path to write the signed file to. |
| signer | The signer object to use for signing. |
| C2paException | for errors encountered by the C2PA library. |
| std::vector< unsigned char > c2pa::Builder::sign | ( | const std::string & | format, |
| std::istream & | source, | ||
| std::iostream & | dest | ||
| ) |
Sign using the signer from the Builder's Context.
The Signer may have been set programmatically via ContextBuilder::with_signer(), or configured in settings JSON. If both programmatic and settings signers are present, the programmatic signer takes priority.
| format | The mime format of the output. |
| source | The input stream to sign. |
| dest | The I/O stream to write the signed data to. |
| C2paException | if the context has no signer or on other errors. |
| std::vector< unsigned char > c2pa::Builder::sign | ( | const std::string & | format, |
| std::istream & | source, | ||
| std::iostream & | dest, | ||
| Signer & | signer | ||
| ) |
Sign an input stream and write the signed data to an I/O stream.
| format | The mime format of the output. |
| source | The input stream to sign. |
| dest | The I/O stream to write the signed data to. |
| signer | The Signer object to use for signing. |
| C2paException | for errors encountered by the C2PA library. |
| std::vector< unsigned char > c2pa::Builder::sign | ( | const std::string & | format, |
| std::istream & | source, | ||
| std::ostream & | dest, | ||
| Signer & | signer | ||
| ) |
Sign an input stream and write the signed data to an output stream.
| format | The mime format of the output stream. |
| source | The input stream to sign. |
| dest | The output stream to write the signed data to. |
| signer | The Signer object to use for signing. |
| C2paException | for errors encountered by the C2PA library. |
| std::vector< unsigned char > c2pa::Builder::sign_data_hashed_embeddable | ( | Signer & | signer, |
| const std::string & | data_hash, | ||
| const std::string & | format, | ||
| std::istream * | asset = nullptr |
||
| ) |
Sign a Builder using the specified signer and data hash.
| signer | The signer to use for signing. |
| data_hash | The data hash ranges to sign (must contain hashes unless an asset is provided). |
| format | The mime format for embedding. Use "c2pa" for an unformatted result. |
| asset | Optional asset to hash according to the data_hash information. |
| C2paException | for errors encountered by the C2PA library. |
| std::vector< unsigned char > c2pa::Builder::sign_embeddable | ( | const std::string & | format | ) |
Sign and return the final manifest bytes, ready for embedding.
Operates in two modes:
| format | The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4"). |
| C2paException | on error. |
|
static |
Get a list of mime types that the Builder supports.
| void c2pa::Builder::to_archive | ( | const std::filesystem::path & | dest_path | ) |
Write the builder to an archive file.
| dest_path | The path to write the archive file to. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::to_archive | ( | std::ostream & | dest | ) |
Write the builder to an archive stream.
| dest | The output stream to write the archive to. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::Builder::update_hash_from_stream | ( | const std::string & | format, |
| std::istream & | stream | ||
| ) |
Compute and store the asset hash by reading a stream.
Automatically detects the hard binding type from the builder state:
| format | The MIME type or extension of the asset (e.g. "image/jpeg", "video/mp4"). |
| stream | The asset stream to hash. Must include the embedded placeholder bytes. |
| C2paException | on error. |
| Builder & c2pa::Builder::with_archive | ( | std::istream & | archive | ) |
Load an archive into this builder.
Replaces the current definition with the archived builder state.
| archive | The input stream to read the archive from. |
| C2paException | for errors encountered by the C2PA library. |
| Builder & c2pa::Builder::with_definition | ( | const std::string & | manifest_json | ) |
Set or update the manifest definition.
| manifest_json | The manifest JSON string. |
| C2pa::C2paException | for errors encountered by the C2PA library. |