|
c2pa-cpp
C++ API for the C2PA SDK
|
Namespaces | |
| namespace | detail |
Classes | |
| class | Builder |
| Builder class for creating a manifest. More... | |
| class | C2paException |
| Exception class for C2pa errors. This class is used to throw exceptions for errors encountered by the C2pa library via c2pa_error(). More... | |
| class | Context |
| C2PA context implementing IContextProvider. More... | |
| class | CppIOStream |
| IOStream Class wrapper for C2paStream. More... | |
| class | CppIStream |
| Input stream IStream wrapper for C2paStream. More... | |
| class | CppOStream |
| Output stream OStream wrapper for C2paStream. More... | |
| class | IContextProvider |
| Interface for types that can provide C2PA context functionality. More... | |
| class | Reader |
| Reader class for reading a manifest. More... | |
| class | Settings |
| (C2PA SDK) Settings configuration object for creating contexts. More... | |
| class | Signer |
| Signer class for creating a Signer. More... | |
Typedefs | |
| typedef C2paSignerInfo | SignerInfo |
| Type alias for C2paSignerInfo from the C API. | |
| using | ProgressCallbackFunc = std::function< bool(ProgressPhase phase, uint32_t step, uint32_t total)> |
| Type alias for the progress callback passed to ContextBuilder::with_progress_callback(). | |
| using | SignerFunc = std::vector< unsigned char >(const std::vector< unsigned char > &) |
| Signer callback function type. | |
Enumerations | |
| enum class | OperationResult : int { Success = 0 , Error = -1 } |
| Result codes for C API operations (matches C API return convention). More... | |
| enum class | StreamError : int { InvalidArgument = EINVAL , IoError = EIO , NoBufferSpace = ENOBUFS } |
| Stream/FFI error codes (maps to errno values used by the C layer). More... | |
| enum class | ProgressPhase : uint8_t { Reading = 0 , VerifyingManifest = 1 , VerifyingSignature = 2 , VerifyingIngredient = 3 , VerifyingAssetHash = 4 , AddingIngredient = 5 , Thumbnail = 6 , Hashing = 7 , Signing = 8 , Embedding = 9 , FetchingRemoteManifest = 10 , Writing = 11 , FetchingOCSP = 12 , FetchingTimestamp = 13 } |
| Phase values reported to the ProgressCallbackFunc. More... | |
Functions | |
| int | stream_error_return (StreamError e) noexcept |
| Set errno from StreamError and return error sentinel. | |
| std::string | version () |
| Get the version of the C2PA library. | |
| void | load_settings (const std::string &data, const std::string &format) |
| Load C2PA settings from a string in a given format. | |
| std::optional< std::string > | read_file (const std::filesystem::path &source_path, const std::optional< std::filesystem::path > data_dir=std::nullopt) |
| Read a file and return the manifest JSON. | |
| std::string | read_ingredient_file (const std::filesystem::path &source_path, const std::filesystem::path &data_dir) |
| Read a file and return an ingredient JSON. | |
| void | sign_file (const std::filesystem::path &source_path, const std::filesystem::path &dest_path, const char *manifest, SignerInfo *signer_info, const std::optional< std::filesystem::path > data_dir=std::nullopt) |
| Add a manifest and sign a file. | |
| using c2pa::ProgressCallbackFunc = typedef std::function<bool(ProgressPhase phase, uint32_t step, uint32_t total)> |
Type alias for the progress callback passed to ContextBuilder::with_progress_callback().
The callback is invoked at each major phase of signing and reading operations. Returning false from the callback aborts the operation with an OperationCancelled error (equivalent to calling Context::cancel()).
| phase | Current operation phase. |
| step | 1-based step index within the phase. 0 = indeterminate (use as liveness signal); resets to 1 at each new phase. |
| total | 0 = indeterminate; 1 = single-shot; >1 = determinate (step/total = fraction). |
| using c2pa::SignerFunc = typedef std::vector<unsigned char>(const std::vector<unsigned char> &) |
Signer callback function type.
This function type is used to create a callback function for signing. The callback receives data to sign and returns the signature.
| data | The data to sign. |
Type alias for C2paSignerInfo from the C API.
|
strong |
Result codes for C API operations (matches C API return convention).
| Enumerator | |
|---|---|
| Success | Operation succeeded. |
| Error | Operation failed (check C2paException for details) |
|
strong |
Phase values reported to the ProgressCallbackFunc.
A scoped C++ mirror of C2paProgressPhase from c2pa.h. Values are verified at compile time to match the C enum, so any future divergence in c2pa-rs will be caught as a build error.
Phases emitted during a typical sign cycle (in order): AddingIngredient → Thumbnail → Hashing → Signing → Embedding → (if verify_after_sign) VerifyingManifest → VerifyingSignature → VerifyingAssetHash → VerifyingIngredient
Phases emitted during reading: Reading → VerifyingManifest → VerifyingSignature → VerifyingAssetHash → VerifyingIngredient
|
strong |
Stream/FFI error codes (maps to errno values used by the C layer).
| Enumerator | |
|---|---|
| InvalidArgument | |
| IoError | |
| NoBufferSpace | |
| void c2pa::load_settings | ( | const std::string & | data, |
| const std::string & | format | ||
| ) |
Load C2PA settings from a string in a given format.
| data | The configuration data to load. |
| format | The mimetype of the string. |
| C2paException | for errors encountered by the C2PA library. |
| std::optional< std::string > c2pa::read_file | ( | const std::filesystem::path & | source_path, |
| const std::optional< std::filesystem::path > | data_dir = std::nullopt |
||
| ) |
Read a file and return the manifest JSON.
| source_path | The path to the file to read. |
| data_dir | Optional directory to store binary resources. |
| C2paException | for errors encountered by the C2PA library. |
| std::string c2pa::read_ingredient_file | ( | const std::filesystem::path & | source_path, |
| const std::filesystem::path & | data_dir | ||
| ) |
Read a file and return an ingredient JSON.
| source_path | The path to the file to read. |
| data_dir | The directory to store binary resources. |
| C2paException | for errors encountered by the C2PA library. |
| void c2pa::sign_file | ( | const std::filesystem::path & | source_path, |
| const std::filesystem::path & | dest_path, | ||
| const char * | manifest, | ||
| SignerInfo * | signer_info, | ||
| const std::optional< std::filesystem::path > | data_dir = std::nullopt |
||
| ) |
Add a manifest and sign a file.
| source_path | The path to the asset to be signed. |
| dest_path | The path to write the signed file to. |
| manifest | The manifest JSON to add to the file. |
| signer_info | The signer info to use for signing. |
| data_dir | Optional directory to store binary resources. |
| C2paException | for errors encountered by the C2PA library. |
|
inlinenoexcept |
Set errno from StreamError and return error sentinel.
| e | The StreamError value to convert to errno. |
| std::string c2pa::version | ( | ) |
Get the version of the C2PA library.