c2pa-cpp
C++ API for the C2PA SDK
Loading...
Searching...
No Matches
c2pa Namespace Reference

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.
 

Typedef Documentation

◆ ProgressCallbackFunc

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()).

Parameters
phaseCurrent operation phase.
step1-based step index within the phase. 0 = indeterminate (use as liveness signal); resets to 1 at each new phase.
total0 = indeterminate; 1 = single-shot; >1 = determinate (step/total = fraction).
Returns
true to continue the operation, false to request cancellation.
Note
The callback must not throw. If it throws, the implementation catches the exception and reports cancellation to the underlying library (same as returning false); the original exception is not propagated. Prefer returning false or using Context::cancel() instead of throwing.

◆ SignerFunc

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.

Parameters
dataThe data to sign.
Returns
The signature as a vector of bytes.

◆ SignerInfo

Type alias for C2paSignerInfo from the C API.

Enumeration Type Documentation

◆ OperationResult

enum class c2pa::OperationResult : int
strong

Result codes for C API operations (matches C API return convention).

Enumerator
Success 

Operation succeeded.

Error 

Operation failed (check C2paException for details)

64 : int {
65 Success = 0, ///< Operation succeeded
66 Error = -1 ///< Operation failed (check C2paException for details)
67 };
@ Success
Operation succeeded.
@ Error
Operation failed (check C2paException for details)

◆ ProgressPhase

enum class c2pa::ProgressPhase : uint8_t
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

Enumerator
Reading 
VerifyingManifest 
VerifyingSignature 
VerifyingIngredient 
VerifyingAssetHash 
AddingIngredient 
Thumbnail 
Hashing 
Signing 
Embedding 
FetchingRemoteManifest 
Writing 
FetchingOCSP 
FetchingTimestamp 

◆ StreamError

enum class c2pa::StreamError : int
strong

Stream/FFI error codes (maps to errno values used by the C layer).

Enumerator
InvalidArgument 
IoError 
NoBufferSpace 
70 : int {
71 InvalidArgument = EINVAL,
72 IoError = EIO,
73 NoBufferSpace = ENOBUFS
74 };

Function Documentation

◆ load_settings()

void c2pa::load_settings ( const std::string &  data,
const std::string &  format 
)

Load C2PA settings from a string in a given format.

Parameters
dataThe configuration data to load.
formatThe mimetype of the string.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Context constructors or Context::ContextBuilder instead for better thread safety.

◆ read_file()

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.

Parameters
source_pathThe path to the file to read.
data_dirOptional directory to store binary resources.
Returns
Optional string containing the manifest JSON if a manifest was found.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Reader object instead.

◆ read_ingredient_file()

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.

Parameters
source_pathThe path to the file to read.
data_dirThe directory to store binary resources.
Returns
String containing the ingredient JSON.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Reader and Builder.add_ingredient instead.

◆ sign_file()

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.

Parameters
source_pathThe path to the asset to be signed.
dest_pathThe path to write the signed file to.
manifestThe manifest JSON to add to the file.
signer_infoThe signer info to use for signing.
data_dirOptional directory to store binary resources.
Exceptions
C2paExceptionfor errors encountered by the C2PA library.
Deprecated:
Use Builder.sign instead.

◆ stream_error_return()

int c2pa::stream_error_return ( StreamError  e)
inlinenoexcept

Set errno from StreamError and return error sentinel.

Parameters
eThe StreamError value to convert to errno.
Returns
OperationResult::Error (-1) for use as C API error return.
79 {
80 errno = static_cast<int>(e);
81 return static_cast<int>(OperationResult::Error);
82 }

◆ version()

std::string c2pa::version ( )

Get the version of the C2PA library.

Returns
Version string.