24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wunused-function"
31#pragma warning(disable : 4505)
80 errno =
static_cast<int>(e);
109 const char*
what() const noexcept override;
112 std::
string message_;
158 [[nodiscard]] virtual C2paContext* c_context() const noexcept = 0;
166 [[nodiscard]] virtual
bool is_valid() const noexcept = 0;
194 Settings(
const std::string& data,
const std::string& format);
209 [[nodiscard]]
bool is_valid() const noexcept;
216 Settings& set(const std::
string& path, const std::
string& json_value);
238 C2paSettings* settings_ptr;
335 [[nodiscard]]
bool is_valid() const noexcept;
353 ContextBuilder& with_json_settings_file(const std::filesystem::path& settings_path);
401 C2paContextBuilder* release() noexcept;
404 C2paContextBuilder* context_builder;
444 [[nodiscard]] C2paContext* c_context() const noexcept override;
449 [[nodiscard]]
bool is_valid() const noexcept override;
465 void cancel() noexcept;
468 C2paContext* context;
472 void* callback_owner_ =
nullptr;
484 [[deprecated("Use
Context::from_json() or
Context::from_settings() instead")]]
485 void C2PA_CPP_API load_settings(const std::
string& data, const std::
string& format);
493 [[deprecated("Use
Reader object instead")]]
494 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);
503 std::
string C2PA_CPP_API read_ingredient_file(const std::filesystem::path &source_path, const std::filesystem::path &data_dir);
513 [[deprecated("Use
Builder.sign instead")]]
515 const std::filesystem::path &dest_path,
516 const
char *manifest,
518 const std::optional<std::filesystem::path> data_dir = std::nullopt);
542 template <
typename IStream>
544 static_assert(std::is_base_of<std::istream, IStream>::value,
545 "Stream must be derived from std::istream");
546 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&istream), reader, seeker, writer, flusher);
547 if (c_stream ==
nullptr) {
548 throw C2paException(
"Failed to create input stream wrapper: is stream open and valid?");
568 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
575 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
582 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
587 static intptr_t flusher(StreamContext *context);
604 template <
typename OStream>
606 static_assert(std::is_base_of<std::ostream, OStream>::value,
"Stream must be derived from std::ostream");
607 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&ostream), reader, seeker, writer, flusher);
608 if (c_stream ==
nullptr) {
609 throw C2paException(
"Failed to create output stream wrapper: is stream open and valid?");
629 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
636 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
643 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
648 static intptr_t flusher(StreamContext *context);
663 template <
typename IOStream>
665 static_assert(std::is_base_of<std::iostream, IOStream>::value,
"Stream must be derived from std::iostream");
666 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&iostream), reader, seeker, writer, flusher);
667 if (c_stream ==
nullptr) {
668 throw C2paException(
"Failed to create I/O stream wrapper: is stream open and valid?");
688 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
695 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
702 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
707 static intptr_t flusher(StreamContext *context);
717 C2paReader *c2pa_reader;
718 std::unique_ptr<std::ifstream> owned_stream;
719 std::unique_ptr<CppIStream> cpp_stream;
744 [[deprecated(
"Use Reader(IContextProvider& context, format, stream) instead")]]
745 Reader(
const std::string &format, std::istream &stream);
752 [[deprecated(
"Use Reader(IContextProvider& context, source_path) instead")]]
753 Reader(
const std::filesystem::path &source_path);
772 : c2pa_reader(std::exchange(other.c2pa_reader,
nullptr)),
773 owned_stream(std::move(other.owned_stream)),
774 cpp_stream(std::move(other.cpp_stream)) {
778 if (
this != &other) {
779 c2pa_free(c2pa_reader);
780 c2pa_reader = std::exchange(other.c2pa_reader,
nullptr);
781 owned_stream = std::move(other.owned_stream);
782 cpp_stream = std::move(other.cpp_stream);
793 return c2pa_reader_is_embedded(c2pa_reader);
813 int64_t
get_resource(
const std::string &uri,
const std::filesystem::path &path);
837 using SignerFunc = std::vector<unsigned char>(
const std::vector<unsigned char> &);
858 C2paSigner* release() noexcept {
859 return std::exchange(signer,
nullptr);
865 static const char *validate_tsa_uri(
const std::string &tsa_uri);
870 static const char *validate_tsa_uri(
const std::optional<std::string> &tsa_uri);
879 Signer(
SignerFunc *callback, C2paSigningAlg alg,
const std::string &sign_cert,
const std::string &tsa_uri);
883 Signer(C2paSigner *c_signer) : signer(c_signer) {
895 Signer(
const std::string &alg,
const std::string &sign_cert,
const std::string &private_key,
const std::optional<std::string> &tsa_uri = std::nullopt);
903 Signer(
Signer&& other) noexcept : signer(std::exchange(other.signer,
nullptr)) {
907 if (
this != &other) {
909 signer = std::exchange(other.signer,
nullptr);
930 C2paBuilder *builder;
950 [[deprecated(
"Use Builder(IContextProvider& context, manifest_json) instead")]]
962 Builder(
Builder&& other) noexcept : builder(std::exchange(other.builder,
nullptr)) {
966 if (
this != &other) {
968 builder = std::exchange(other.builder,
nullptr);
983 Builder& with_definition(const std::
string &manifest_json);
992 void set_remote_url(const std::
string &remote_url);
1001 void set_base_path(const std::
string &base_path);
1007 void add_resource(const std::
string &uri, std::istream &source);
1014 void add_resource(const std::
string &uri, const std::filesystem::path &source_path);
1021 void add_ingredient(const std::
string &ingredient_json, const std::
string &format, std::istream &source);
1028 void add_ingredient(const std::
string &ingredient_json, const std::filesystem::path &source_path);
1033 void add_action(const std::
string &action_json);
1040 void set_intent(C2paBuilderIntent intent, C2paDigitalSourceType digital_source_type = Empty);
1050 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::ostream &dest,
Signer &signer);
1059 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::iostream &dest,
Signer &signer);
1068 std::vector<
unsigned char> sign(const std::filesystem::path &source_path, const std::filesystem::path &dest_path,
Signer &signer);
1080 std::vector<
unsigned char> sign(const std::
string &format, std::istream &source, std::iostream &dest);
1091 std::vector<
unsigned char> sign(const std::filesystem::path &source_path, const std::filesystem::path &dest_path);
1097 static
Builder from_archive(std::istream &archive);
1104 static
Builder from_archive(const std::filesystem::path &archive_path);
1117 void to_archive(std::ostream &dest);
1123 void to_archive(const std::filesystem::path &dest_path);
1130 std::vector<
unsigned char> data_hashed_placeholder(uintptr_t reserved_size, const std::
string &format);
1139 std::vector<
unsigned char> sign_data_hashed_embeddable(
Signer &signer, const std::
string &data_hash, const std::
string &format, std::istream *asset =
nullptr);
1145 static std::vector<
unsigned char> format_embeddable(const std::
string &format, std::vector<
unsigned char> &data);
1154 bool needs_placeholder(const std::
string &format);
1166 std::vector<
unsigned char> placeholder(const std::
string &format);
1175 void set_data_hash_exclusions(const std::vector<std::pair<uint64_t, uint64_t>> &exclusions);
1186 void update_hash_from_stream(const std::
string &format, std::istream &stream);
1198 std::vector<
unsigned char> sign_embeddable(const std::
string &format);
1202 static std::vector<std::
string> supported_mime_types();
1205 explicit
Builder(std::istream &archive);
1211#pragma GCC diagnostic pop
#define C2PA_CPP_API
Definition c2pa.hpp:49
Builder class for creating a manifest.
Definition c2pa.hpp:928
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:962
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:965
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:87
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:320
~ContextBuilder() noexcept
C2PA context implementing IContextProvider.
Definition c2pa.hpp:312
IOStream Class wrapper for C2paStream.
Definition c2pa.hpp:654
CppIOStream & operator=(const CppIOStream &)=delete
CppIOStream(const CppIOStream &)=delete
CppIOStream & operator=(CppIOStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:657
CppIOStream(IOStream &iostream)
Construct an I/O stream wrapper from a std::iostream-derived object.
Definition c2pa.hpp:664
CppIOStream(CppIOStream &&)=delete
Input stream IStream wrapper for C2paStream.
Definition c2pa.hpp:533
CppIStream & operator=(const CppIStream &)=delete
CppIStream(CppIStream &&)=delete
CppIStream & operator=(CppIStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:536
CppIStream(IStream &istream)
Construct an input stream wrapper from a std::istream-derived object.
Definition c2pa.hpp:543
CppIStream(const CppIStream &)=delete
Output stream OStream wrapper for C2paStream.
Definition c2pa.hpp:595
CppOStream(OStream &ostream)
Construct an output stream wrapper from a std::ostream-derived object.
Definition c2pa.hpp:605
CppOStream(CppOStream &&)=delete
CppOStream & operator=(CppOStream &&)=delete
C2paStream * c_stream
Pointer to the underlying C2paStream.
Definition c2pa.hpp:598
CppOStream & operator=(const CppOStream &)=delete
CppOStream(const CppOStream &)=delete
Interface for types that can provide C2PA context functionality.
Definition c2pa.hpp:151
virtual ~IContextProvider() noexcept=default
Reader class for reading a manifest.
Definition c2pa.hpp:715
bool is_embedded() const
Check if the reader was created from an embedded manifest.
Definition c2pa.hpp:792
std::string json() const
Get the manifest as a JSON string.
static std::optional< Reader > from_asset(IContextProvider &context, const std::string &format, std::istream &stream)
Try to create a Reader from a context and stream when the asset may lack C2PA data.
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.
static std::optional< Reader > from_asset(IContextProvider &context, const std::filesystem::path &source_path)
Try to open a Reader from a context and file path when the asset may lack C2PA data.
Reader(Reader &&other) noexcept
Definition c2pa.hpp:771
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:777
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:825
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:185
Settings & update(const std::string &data)
Merge configuration from a JSON string (latest configuration wins).
Definition c2pa.hpp:223
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:843
Signer & operator=(Signer &&other) noexcept
Definition c2pa.hpp:906
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:883
Signer & operator=(const Signer &)=delete
Signer(Signer &&other) noexcept
Move constructor.
Definition c2pa.hpp:903
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:64
@ Success
Operation succeeded.
@ Error
Operation failed (check C2paException for details)
ProgressPhase
Phase values reported to the ProgressCallbackFunc.
Definition c2pa.hpp:255
std::function< bool(ProgressPhase phase, uint32_t step, uint32_t total)> ProgressCallbackFunc
Type alias for the progress callback passed to ContextBuilder::with_progress_callback().
Definition c2pa.hpp:289
int stream_error_return(StreamError e) noexcept
Set errno from StreamError and return error sentinel.
Definition c2pa.hpp:79
C2paSignerInfo SignerInfo
Type alias for C2paSignerInfo from the C API.
Definition c2pa.hpp:55
StreamError
Stream/FFI error codes (maps to errno values used by the C layer).
Definition c2pa.hpp:70
std::vector< unsigned char >(const std::vector< unsigned char > &) SignerFunc
Signer callback function type.
Definition c2pa.hpp:837