24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wunused-function"
31#pragma warning(disable : 4505)
43using path = std::filesystem::path;
66 virtual const char *
what() const noexcept;
76 void C2PA_CPP_API load_settings(const
string& data, const
string& format);
83 optional<
string>
C2PA_CPP_API read_file(const filesystem::
path &source_path, const optional<
path> data_dir = nullopt);
100 const
path &dest_path,
101 const
char *manifest,
103 const std::optional<
path> data_dir = std::nullopt);
111 template <
typename IStream>
113 static_assert(std::is_base_of<std::istream, IStream>::value,
114 "Stream must be derived from std::istream");
115 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&istream), reader, seeker, writer, flusher);
126 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
127 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
128 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
129 static intptr_t flusher(StreamContext *context);
140 template <
typename OStream>
142 static_assert(std::is_base_of<std::ostream, OStream>::value,
"Stream must be derived from std::ostream");
143 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&ostream), reader, seeker, writer, flusher);
149 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
150 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
151 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
152 static intptr_t flusher(StreamContext *context);
161 template <
typename IOStream>
163 static_assert(std::is_base_of<std::iostream, IOStream>::value,
"Stream must be derived from std::iostream");
164 c_stream = c2pa_create_stream(
reinterpret_cast<StreamContext *
>(&iostream), reader, seeker, writer, flusher);
169 static intptr_t reader(StreamContext *context, uint8_t *buffer, intptr_t size);
170 static intptr_t writer(StreamContext *context,
const uint8_t *buffer, intptr_t size);
171 static intptr_t seeker(StreamContext *context, intptr_t offset, C2paSeekMode whence);
172 static intptr_t flusher(StreamContext *context);
180 C2paReader *c2pa_reader;
189 Reader(
const std::string &format, std::istream &stream);
194 Reader(
const std::filesystem::path &source_path);
200 return c2pa_reader_is_embedded(c2pa_reader);
241 using SignerFunc = std::vector<unsigned char>(
const std::vector<unsigned char> &);
256 Signer(
SignerFunc *callback, C2paSigningAlg alg,
const string &sign_cert,
const string &tsa_uri);
258 Signer(C2paSigner *signer) : signer(signer) {}
260 Signer(
const string &alg,
const string &sign_cert,
const string&private_key,
const string &tsa_uri = NULL);
277 C2paBuilder *builder;
313 void add_resource(
const string &uri,
const std::filesystem::path &source_path);
320 void add_ingredient(
const string &ingredient_json,
const string &format, istream &source);
326 void add_ingredient(
const string &ingredient_json,
const std::filesystem::path &source_path);
341 std::vector<unsigned char>
sign(
const string &format, istream &source, ostream &dest,
Signer &signer);
350 std::vector<unsigned char>
sign(
const string &format, istream &source, iostream &dest,
Signer &signer);
400 static std::vector<unsigned char>
format_embeddable(
const string &format, std::vector<unsigned char> &data);
407 explicit Builder(istream &archive);
413#pragma GCC diagnostic pop
#define C2PA_CPP_API
Definition c2pa.hpp:46
std::filesystem::path path
Definition c2pa.hpp:43
Builder class for creating a manifest.
Definition c2pa.hpp:275
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.
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 to_archive(const path &dest_path)
Write the builder to an archive file.
void add_ingredient(const string &ingredient_json, const std::filesystem::path &source_path)
Add an ingredient to the builder.
std::vector< unsigned char > sign(const path &source_path, const path &dest_path, Signer &signer)
Sign a file and write the signed data to an output 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.
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:158
C2paStream * c_stream
Definition c2pa.hpp:160
CppIOStream(IOStream &iostream)
Definition c2pa.hpp:162
Istream Class wrapper for C2paStream.
Definition c2pa.hpp:108
CppIStream & operator=(const CppIStream &)=delete
CppIStream(CppIStream &&)=delete
CppIStream & operator=(CppIStream &&)=delete
C2paStream * c_stream
Definition c2pa.hpp:110
CppIStream(IStream &istream)
Definition c2pa.hpp:112
CppIStream(const CppIStream &)=delete
Ostream Class wrapper for C2paStream.
Definition c2pa.hpp:137
CppOStream(OStream &ostream)
Definition c2pa.hpp:141
C2paStream * c_stream
Definition c2pa.hpp:139
Reader class for reading a manifest.
Definition c2pa.hpp:178
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:199
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:230
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:246
Signer(const string &alg, const string &sign_cert, const string &private_key, const string &tsa_uri=NULL)
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:258
C2paSignerInfo SignerInfo
Definition c2pa.hpp:52
std::vector< unsigned char >(const std::vector< unsigned char > &) SignerFunc
Signer Callback function type.
Definition c2pa.hpp:241