24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wunused-function"
31#pragma warning(disable : 4505)
79 errno =
static_cast<int>(e);
108 const char*
what() const noexcept override;
111 std::
string message_;
157 [[nodiscard]] virtual C2paContext* c_context() const noexcept = 0;
165 [[nodiscard]] virtual
bool is_valid() const noexcept = 0;
193 Settings(
const std::string& data,
const std::string& format);
208 [[nodiscard]]
bool is_valid() const noexcept;
215 Settings& set(const std::
string& path, const std::
string& json_value);
237 C2paSettings* settings_ptr;
284 [[nodiscard]]
bool is_valid() const noexcept;
302 ContextBuilder& with_json_settings_file(const std::filesystem::path& settings_path);
321 C2paContextBuilder* context_builder;
360 [[nodiscard]] C2paContext* c_context() const noexcept override;
365 [[nodiscard]]
bool is_valid() const noexcept override;
373 C2paContext* context;
385 [[deprecated("Use
Context::from_json() or
Context::from_settings() instead")]]
386 void C2PA_CPP_API load_settings(const std::
string& data, const std::
string& format);
394 [[deprecated("Use
Reader object instead")]]
395 std::optional<std::
string>
C2PA_CPP_API read_file(const std::filesystem::path &source_path, const std::optional<std::filesystem::path> data_dir = std::nullopt);
404 std::
string C2PA_CPP_API read_ingredient_file(const std::filesystem::path &source_path, const std::filesystem::path &data_dir);
414 [[deprecated("Use
Builder.sign instead")]]
416 const std::filesystem::path &dest_path,
417 const
char *manifest,
419 const std::optional<std::filesystem::path> data_dir = std::nullopt);
443 template <
typename IStream>
445 static_assert(std::is_base_of<std::istream, IStream>::value,
446 "Stream must be derived from std::istream");
447 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&istream), reader, seeker, writer, flusher);
448 if (c_stream ==
nullptr) {
449 throw C2paException(
"Failed to create input stream wrapper: is stream open and valid?");
469 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
476 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
483 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
488 static intptr_t flusher(StreamContext *context);
505 template <
typename OStream>
507 static_assert(std::is_base_of<std::ostream, OStream>::value,
"Stream must be derived from std::ostream");
508 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&ostream), reader, seeker, writer, flusher);
509 if (c_stream ==
nullptr) {
510 throw C2paException(
"Failed to create output stream wrapper: is stream open and valid?");
530 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
537 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
544 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
549 static intptr_t flusher(StreamContext *context);
564 template <
typename IOStream>
566 static_assert(std::is_base_of<std::iostream, IOStream>::value,
"Stream must be derived from std::iostream");
567 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&iostream), reader, seeker, writer, flusher);
568 if (c_stream ==
nullptr) {
569 throw C2paException(
"Failed to create I/O stream wrapper: is stream open and valid?");
589 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
596 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
603 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
608 static intptr_t flusher(StreamContext *context);
618 C2paReader *c2pa_reader;
619 std::unique_ptr<std::ifstream> owned_stream;
620 std::unique_ptr<CppIStream> cpp_stream;
645 [[deprecated(
"Use Reader(IContextProvider& context, format, stream) instead")]]
646 Reader(
const std::string &format, std::istream &stream);
653 [[deprecated(
"Use Reader(IContextProvider& context, source_path) instead")]]
654 Reader(
const std::filesystem::path &source_path);
662 : c2pa_reader(std::exchange(other.c2pa_reader,
nullptr)),
663 owned_stream(std::move(other.owned_stream)),
664 cpp_stream(std::move(other.cpp_stream)) {
668 if (
this != &other) {
669 c2pa_free(c2pa_reader);
670 c2pa_reader = std::exchange(other.c2pa_reader,
nullptr);
671 owned_stream = std::move(other.owned_stream);
672 cpp_stream = std::move(other.cpp_stream);
683 return c2pa_reader_is_embedded(c2pa_reader);
703 int64_t
get_resource(
const std::string &uri,
const std::filesystem::path &path);
727 using SignerFunc = std::vector<unsigned char>(
const std::vector<unsigned char> &);
748 C2paSigner* release() noexcept {
749 return std::exchange(signer,
nullptr);
755 static const char *validate_tsa_uri(
const std::string &tsa_uri);
760 static const char *validate_tsa_uri(
const std::optional<std::string> &tsa_uri);
769 Signer(
SignerFunc *callback, C2paSigningAlg alg,
const std::string &sign_cert,
const std::string &tsa_uri);
773 Signer(C2paSigner *c_signer) : signer(c_signer) {
785 Signer(
const std::string &alg,
const std::string &sign_cert,
const std::string &private_key,
const std::optional<std::string> &tsa_uri = std::nullopt);
793 Signer(
Signer&& other) noexcept : signer(std::exchange(other.signer,
nullptr)) {
797 if (
this != &other) {
799 signer = std::exchange(other.signer,
nullptr);
820 C2paBuilder *builder;
840 [[deprecated(
"Use Builder(IContextProvider& context, manifest_json) instead")]]
852 Builder(
Builder&& other) noexcept : builder(std::exchange(other.builder,
nullptr)) {
856 if (
this != &other) {
858 builder = std::exchange(other.builder,
nullptr);
873 Builder& with_definition(const std::
string &manifest_json);
882 void set_remote_url(const std::
string &remote_url);
891 void set_base_path(const std::
string &base_path);
897 void add_resource(const std::
string &uri, std::istream &source);
904 void add_resource(const std::
string &uri, const std::filesystem::path &source_path);
911 void add_ingredient(const std::
string &ingredient_json, const std::
string &format, std::istream &source);
918 void add_ingredient(const std::
string &ingredient_json, const std::filesystem::path &source_path);
923 void add_action(const std::
string &action_json);
930 void set_intent(C2paBuilderIntent intent, C2paDigitalSourceType digital_source_type = Empty);
940 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::ostream &dest,
Signer &signer);
949 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::iostream &dest,
Signer &signer);
958 std::vector<
unsigned char> sign(const std::filesystem::path &source_path, const std::filesystem::path &dest_path,
Signer &signer);
970 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::iostream &dest);
981 std::vector<
unsigned char> sign(const std::filesystem::path &source_path, const std::filesystem::path &dest_path);
987 static
Builder from_archive(std::istream &archive);
994 static
Builder from_archive(const std::filesystem::path &archive_path);
1007 void to_archive(std::ostream &dest);
1013 void to_archive(const std::filesystem::path &dest_path);
1020 std::vector<
unsigned char> data_hashed_placeholder(uintptr_t reserved_size, const std::
string &format);
1029 std::vector<
unsigned char> sign_data_hashed_embeddable(
Signer &signer, const std::
string &data_hash, const std::
string &format, std::istream *asset =
nullptr);
1035 static std::vector<
unsigned char> format_embeddable(const std::
string &format, std::vector<
unsigned char> &data);
1044 bool needs_placeholder(const std::
string &format);
1056 std::vector<
unsigned char> placeholder(const std::
string &format);
1065 void set_data_hash_exclusions(const std::vector<std::pair<uint64_t, uint64_t>> &exclusions);
1076 void update_hash_from_stream(const std::
string &format, std::istream &stream);
1088 std::vector<
unsigned char> sign_embeddable(const std::
string &format);
1092 static std::vector<std::
string> supported_mime_types();
1095 explicit
Builder(std::istream &archive);
1101#pragma GCC diagnostic pop
#define C2PA_CPP_API
Definition c2pa.hpp:48
Builder class for creating a manifest.
Definition c2pa.hpp:818
Builder(const std::string &manifest_json)
Create a Builder from a manifest JSON string (will use global settings if any loaded).
Builder & operator=(const Builder &)=delete
Builder(Builder &&other) noexcept
Definition c2pa.hpp:852
Builder(C2paBuilder *builder)
Create a Builder from a raw C FFI builder.
Builder(const Builder &)=delete
C2paBuilder * c2pa_builder() const noexcept
Get the underlying C2paBuilder pointer.
Builder & operator=(Builder &&other) noexcept
Definition c2pa.hpp:855
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.
Exception class for C2pa errors. This class is used to throw exceptions for errors encountered by the...
Definition c2pa.hpp:86
C2paException & operator=(C2paException &&)=default
~C2paException() override=default
C2paException(const C2paException &)=default
const char * what() const noexcept override
Get the exception message.
C2paException(std::string message)
Construct an exception with a custom error message.
C2paException & operator=(const C2paException &)=default
C2paException(C2paException &&)=default
C2paException()
Default constructor.
ContextBuilder for creating customized Context instances.
Definition c2pa.hpp:269
~ContextBuilder() noexcept
C2PA context implementing IContextProvider.
Definition c2pa.hpp:261
IOStream Class wrapper for C2paStream.
Definition c2pa.hpp:555
CppIOStream & operator=(const CppIOStream &)=delete
CppIOStream(const CppIOStream &)=delete
CppIOStream & operator=(CppIOStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:558
CppIOStream(IOStream &iostream)
Construct an I/O stream wrapper from a std::iostream-derived object.
Definition c2pa.hpp:565
CppIOStream(CppIOStream &&)=delete
Input stream IStream wrapper for C2paStream.
Definition c2pa.hpp:434
CppIStream & operator=(const CppIStream &)=delete
CppIStream(CppIStream &&)=delete
CppIStream & operator=(CppIStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:437
CppIStream(IStream &istream)
Construct an input stream wrapper from a std::istream-derived object.
Definition c2pa.hpp:444
CppIStream(const CppIStream &)=delete
Output stream OStream wrapper for C2paStream.
Definition c2pa.hpp:496
CppOStream(OStream &ostream)
Construct an output stream wrapper from a std::ostream-derived object.
Definition c2pa.hpp:506
CppOStream(CppOStream &&)=delete
CppOStream & operator=(CppOStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:499
CppOStream & operator=(const CppOStream &)=delete
CppOStream(const CppOStream &)=delete
Interface for types that can provide C2PA context functionality.
Definition c2pa.hpp:150
virtual ~IContextProvider() noexcept=default
Reader class for reading a manifest.
Definition c2pa.hpp:616
bool is_embedded() const
Check if the reader was created from an embedded manifest.
Definition c2pa.hpp:682
std::string json() const
Get the manifest as a JSON string.
int64_t get_resource(const std::string &uri, const std::filesystem::path &path)
Get a resource from the reader and write it to a file.
Reader(const std::string &format, std::istream &stream)
Create a Reader from a stream (will use global settings if any loaded).
int64_t get_resource(const std::string &uri, std::ostream &stream)
Get a resource from the reader and write it to an output stream.
Reader(Reader &&other) noexcept
Definition c2pa.hpp:661
Reader(const Reader &)=delete
Reader & operator=(const Reader &)=delete
std::optional< std::string > remote_url() const
Returns the remote url of the manifest if this Reader obtained the manifest remotely.
Reader(IContextProvider &context, const std::string &format, std::istream &stream)
Create a Reader from a context and stream.
Reader & operator=(Reader &&other) noexcept
Definition c2pa.hpp:667
Reader(const std::filesystem::path &source_path)
Create a Reader from a file path (will use global settings if any loaded).
C2paReader * get_api_internal_raw_reader() const
Get the raw C2paReader pointer.
Definition c2pa.hpp:715
Reader(IContextProvider &context, const std::filesystem::path &source_path)
Create a Reader from a context and file path.
static std::vector< std::string > supported_mime_types()
Get a list of mime types that the SDK can read manifests from.
(C2PA SDK) Settings configuration object for creating contexts.
Definition c2pa.hpp:184
Settings & update(const std::string &data)
Merge configuration from a JSON string (latest configuration wins).
Definition c2pa.hpp:222
C2paSettings * c_settings() const noexcept
Get the raw C FFI settings pointer.
Settings(const std::string &data, const std::string &format)
Create settings from a configuration string.
Settings()
Create default settings.
Settings(Settings &&) noexcept
Settings & update(const std::string &data, const std::string &format)
Merge configuration from a std::string (latest configuration wins).
Signer class for creating a Signer.
Definition c2pa.hpp:733
Signer & operator=(Signer &&other) noexcept
Definition c2pa.hpp:796
uintptr_t reserve_size()
Get the size to reserve for a signature for this Signer.
C2paSigner * c2pa_signer() const noexcept
Get the underlying C2paSigner pointer.
Signer(SignerFunc *callback, C2paSigningAlg alg, const std::string &sign_cert, const std::string &tsa_uri)
Create a Signer from a callback function.
Signer(C2paSigner *c_signer)
Create a signer from a Signer pointer and take ownership of that pointer.
Definition c2pa.hpp:773
Signer & operator=(const Signer &)=delete
Signer(Signer &&other) noexcept
Move constructor.
Definition c2pa.hpp:793
Signer(const Signer &)=delete
Signer(const std::string &alg, const std::string &sign_cert, const std::string &private_key, const std::optional< std::string > &tsa_uri=std::nullopt)
Create a Signer from signing credentials.
OperationResult
Result codes for C API operations (matches C API return convention).
Definition c2pa.hpp:63
@ Success
Operation succeeded.
@ Error
Operation failed (check C2paException for details)
int stream_error_return(StreamError e) noexcept
Set errno from StreamError and return error sentinel.
Definition c2pa.hpp:78
C2paSignerInfo SignerInfo
Type alias for C2paSignerInfo from the C API.
Definition c2pa.hpp:54
StreamError
Stream/FFI error codes (maps to errno values used by the C layer).
Definition c2pa.hpp:69
std::vector< unsigned char >(const std::vector< unsigned char > &) SignerFunc
Signer callback function type.
Definition c2pa.hpp:727