24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wunused-function"
31#pragma warning(disable : 4505)
64 virtual const char *
what() const noexcept;
74 void C2PA_CPP_API load_settings(const
string& data, const
string& format);
81 optional<
string>
C2PA_CPP_API read_file(const std::filesystem::path &source_path, const optional<std::filesystem::path> data_dir = nullopt);
88 std::
string C2PA_CPP_API read_ingredient_file(const std::filesystem::path &source_path, const std::filesystem::path &data_dir);
97 void C2PA_CPP_API sign_file(const std::filesystem::path &source_path,
98 const std::filesystem::path &dest_path,
101 const std::optional<std::filesystem::path> data_dir = std::nullopt);
109 template <
typename IStream>
111 static_assert(std::is_base_of<std::istream, IStream>::value,
112 "Stream must be derived from std::istream");
113 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&istream), reader, seeker, writer, flusher);
124 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
125 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
126 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
127 static intptr_t flusher(StreamContext *context);
138 template <
typename OStream>
140 static_assert(std::is_base_of<std::ostream, OStream>::value,
"Stream must be derived from std::ostream");
141 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&ostream), reader, seeker, writer, flusher);
147 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
148 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
149 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
150 static intptr_t flusher(StreamContext *context);
159 template <
typename IOStream>
161 static_assert(std::is_base_of<std::iostream, IOStream>::value,
"Stream must be derived from std::iostream");
162 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&iostream), reader, seeker, writer, flusher);
167 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
168 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
169 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
170 static intptr_t flusher(StreamContext *context);
178 C2paReader *c2pa_reader;
187 Reader(
const std::string &format, std::istream &stream);
192 Reader(
const std::filesystem::path &source_path);
198 return c2pa_reader_is_embedded(c2pa_reader);
216 int64_t
get_resource(
const string &uri,
const std::filesystem::path &path);
239 using SignerFunc = std::vector<unsigned char>(
const std::vector<unsigned char> &);
254 Signer(
SignerFunc *callback, C2paSigningAlg alg,
const string &sign_cert,
const string &tsa_uri);
256 Signer(C2paSigner *signer) : signer(signer) {}
258 Signer(
const string &alg,
const string &sign_cert,
const string &private_key,
const optional<string> &tsa_uri = nullopt);
275 C2paBuilder *builder;
315 void add_resource(
const string &uri,
const std::filesystem::path &source_path);
322 void add_ingredient(
const string &ingredient_json,
const string &format, istream &source);
328 void add_ingredient(
const string &ingredient_json,
const std::filesystem::path &source_path);
343 std::vector<unsigned char>
sign(
const string &format, istream &source, ostream &dest,
Signer &signer);
352 std::vector<unsigned char>
sign(
const string &format, istream &source, iostream &dest,
Signer &signer);
360 std::vector<unsigned char>
sign(
const std::filesystem::path &source_path,
const std::filesystem::path &dest_path,
Signer &signer);
402 static std::vector<unsigned char>
format_embeddable(
const string &format, std::vector<unsigned char> &data);
409 explicit Builder(istream &archive);
415#pragma GCC diagnostic pop
#define C2PA_CPP_API
Definition c2pa.hpp:44
Builder class for creating a manifest.
Definition c2pa.hpp:273
void add_ingredient(const string &ingredient_json, const string &format, istream &source)
Add an ingredient to the builder.
Builder(const std::string &manifest_json)
Create a Builder from a manifest JSON string.
void set_remote_url(const string &remote_url)
Set the remote URL.
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.
void to_archive(ostream &dest)
Write the builder to an archive stream.
void add_resource(const string &uri, const std::filesystem::path &source_path)
Add a resource to the builder.
void add_ingredient(const string &ingredient_json, const std::filesystem::path &source_path)
Add an ingredient to the builder.
void to_archive(const std::filesystem::path &dest_path)
Write the builder to an archive file.
void set_no_embed()
Set the no embed flag.
void add_action(const string &action_json)
Add an action to the manifest the Builder is constructing.
std::vector< unsigned char > sign(const string &format, istream &source, ostream &dest, Signer &signer)
Sign an input stream and write the signed data to an output stream.
static std::vector< unsigned char > format_embeddable(const string &format, std::vector< unsigned char > &data)
convert an unformatted manifest data to an embeddable format.
std::vector< unsigned char > sign_data_hashed_embeddable(Signer &signer, const string &data_hash, const string &format, istream *asset=nullptr)
Sign a Builder using the specified signer and data hash.
static Builder from_archive(const std::filesystem::path &archive_path)
Create a Builder from an archive.
std::vector< unsigned char > data_hashed_placeholder(uintptr_t reserved_size, const string &format)
Create a hashed placeholder from the builder.
C2paBuilder * c2pa_builder()
Get the underlying C2paBuilder pointer.
void add_resource(const string &uri, istream &source)
Add a resource to the builder.
std::vector< unsigned char > sign(const string &format, istream &source, iostream &dest, Signer &signer)
Sign an input stream and write the signed data to an output stream.
static std::vector< std::string > supported_mime_types()
Returns a vector of mime types that the SDK is able to sign.
static Builder from_archive(istream &archive)
Create a Builder from an archive.
void set_base_path(const string &base_path)
Set the base path for loading resources from files. Loads from memory if this is not set.
virtual const char * what() const noexcept
C2paException(string what)
IOStream Class wrapper for C2paStream.
Definition c2pa.hpp:156
C2paStream * c_stream
Definition c2pa.hpp:158
CppIOStream(IOStream &iostream)
Definition c2pa.hpp:160
Istream Class wrapper for C2paStream.
Definition c2pa.hpp:106
CppIStream & operator=(const CppIStream &)=delete
CppIStream(CppIStream &&)=delete
CppIStream & operator=(CppIStream &&)=delete
C2paStream * c_stream
Definition c2pa.hpp:108
CppIStream(IStream &istream)
Definition c2pa.hpp:110
CppIStream(const CppIStream &)=delete
Ostream Class wrapper for C2paStream.
Definition c2pa.hpp:135
CppOStream(OStream &ostream)
Definition c2pa.hpp:139
C2paStream * c_stream
Definition c2pa.hpp:137
Reader class for reading a manifest.
Definition c2pa.hpp:176
int64_t get_resource(const string &uri, const std::filesystem::path &path)
Get a resource from the reader and write it to a file.
bool is_embedded() const
Returns if the reader was created from an embedded manifest.
Definition c2pa.hpp:197
Reader(const std::string &format, std::istream &stream)
Create a Reader from a stream.
std::optional< std::string > remote_url() const
Returns the remote url of the manifest if this Reader obtained the manifest remotely.
int64_t get_resource(const string &uri, std::ostream &stream)
Get a resource from the reader and write it to an output stream.
string json()
Get the manifest as a json string.
Reader(const std::filesystem::path &source_path)
Create a Reader from a file path.
C2paReader * get_api_internal_raw_reader() const
Get the raw C2paReader pointer.
Definition c2pa.hpp:228
static std::vector< std::string > supported_mime_types()
Returns a vector of mime types that the SDK is able to read manifests from.
Signer class for creating a signer.
Definition c2pa.hpp:244
Signer(const string &alg, const string &sign_cert, const string &private_key, const optional< string > &tsa_uri=nullopt)
Signer(SignerFunc *callback, C2paSigningAlg alg, const string &sign_cert, const string &tsa_uri)
Create a Signer from a callback function, signing algorithm, certificate, and TSA URI.
uintptr_t reserve_size()
Get the size to reserve for a signature for this signer.
C2paSigner * c2pa_signer()
Get the C2paSigner.
Signer(C2paSigner *signer)
Definition c2pa.hpp:256
C2paSignerInfo SignerInfo
Definition c2pa.hpp:50
std::vector< unsigned char >(const std::vector< unsigned char > &) SignerFunc
Signer Callback function type.
Definition c2pa.hpp:239