From d0354028e34c0726d2a45ffcef11063c9604cdac Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 10 Feb 2026 09:06:09 -0800 Subject: [PATCH 1/3] fix: Drop from_toml API, fix typos --- README.md | 8 ++++---- include/c2pa.hpp | 10 ++-------- src/c2pa.cpp | 4 ---- tests/builder.test.cpp | 6 +++--- tests/context.test.cpp | 21 ++++----------------- tests/cpp-app-test/test.cpp | 2 +- tests/reader.test.cpp | 2 +- 7 files changed, 15 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 492b56e6..ebfa8136 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ This will automatically fetch, build, and link the `c2pa_cpp` library and its de ### Example usage -See the [`examples/`](examples/) directory for sample applications that demonstrate how to use the library in practice. +See the [`examples/`](examples/) directory for sample applications that demonstrate how to use the library in practice. ## Development @@ -49,7 +49,7 @@ This project has been tested on macOS and should also work on common Linux distr You must install the [Ninja](https://github.com/ninja-build/ninja/wiki/Pre-built-Ninja-packages) build system to run the unit tests. -### Building using pre-build C FFI libraries +### Building using pre-built C FFI libraries Building the library holding the C++ SDK requires [GNU make](https://www.gnu.org/software/make/), which is installed on most macOS systems. @@ -72,7 +72,7 @@ Results are saved in the `build` directory. This project can also be built entirely from source (without pre-built library download), with the pre-requisite that you will also need [c2pa-rs](https://github.com/contentauth/c2pa-rs) on the local machine, as well as the [Rust toolchain](https://rust-lang.org/tools/install/). -To build in this case, the build scripts need to be able to locate the `c2pa-rs` sources as well as the librari this builds for linking. This is done by setting environment variables in the terminal where the builds will run. +To build in this case, the build scripts need to be able to locate the `c2pa-rs` sources as well as the library this builds for linking. This is done by setting environment variables in the terminal where the builds will run. ```sh # Enable local c2pa-rs build @@ -81,7 +81,7 @@ export C2PA_BUILD_FROM_SOURCE=ON # If local build is enabled, set this environment variable to contain the path to c2pa-rs sources export C2PA_RS_PATH=path_to_c2pa_rs_sources -# Since this is going to build Rust code, the build sysstem need to locate cargo, the tool to build RUst code +# Since this is going to build Rust code, the build system needs to locate cargo, the tool to build Rust code # Add Rust cargo to PATH if not already there export PATH="$HOME/.cargo/bin:$PATH" diff --git a/include/c2pa.hpp b/include/c2pa.hpp index ea3887c3..0591c76f 100644 --- a/include/c2pa.hpp +++ b/include/c2pa.hpp @@ -287,12 +287,6 @@ namespace c2pa /// @throws C2paException if JSON is invalid or context creation fails. [[nodiscard]] static std::shared_ptr from_json(const std::string& json); - /// @brief Create a Context from TOML configuration (settings). - /// @param toml TOML configuration string. - /// @return Shared pointer to the new Context. - /// @throws C2paException if TOML is invalid or context creation fails. - [[nodiscard]] static std::shared_ptr from_toml(const std::string& toml); - // Non-copyable, non-moveable Context(const Context&) = delete; Context& operator=(const Context&) = delete; @@ -321,8 +315,8 @@ namespace c2pa /// @param data the std::string to load. /// @param format the mime format of the string. /// @throws a C2pa::C2paException for errors encountered by the C2PA library. - /// @deprecated Use Context::from_json() or Context::from_toml() instead for better thread safety. - [[deprecated("Use Context pattern instead, Context::from_json() or Context::from_toml() instead")]] + /// @deprecated Use Context::from_json() or Context::ContextBuilder().with_toml().create_context() instead for better thread safety. + [[deprecated("Use Context pattern instead, Context::from_json() or Context::ContextBuilder().with_toml().create_context() instead")]] void C2PA_CPP_API load_settings(const std::string& data, const std::string& format); /// Reads a file and returns the manifest json as a C2pa::String. diff --git a/src/c2pa.cpp b/src/c2pa.cpp index 616b6c2d..1a99f9e7 100644 --- a/src/c2pa.cpp +++ b/src/c2pa.cpp @@ -411,10 +411,6 @@ inline std::vector to_byte_vector(const unsigned char* data, int6 return ContextBuilder().with_json(json).create_context(); } - std::shared_ptr Context::from_toml(const std::string& toml) { - return ContextBuilder().with_toml(toml).create_context(); - } - // Context::ContextBuilder Context::ContextBuilder::ContextBuilder() : context_builder(c2pa_context_builder_new()) { diff --git a/tests/builder.test.cpp b/tests/builder.test.cpp index c71b1e00..45d74910 100644 --- a/tests/builder.test.cpp +++ b/tests/builder.test.cpp @@ -892,7 +892,7 @@ TEST_F(BuilderTest, SignImageThumbnailSettingsFileToml) // Create context with specific settings via toml, by loading the TOML file fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_no_thumbnail.toml"; auto settings_toml = c2pa_test::read_text_file(settings_path); - auto context = c2pa::Context::from_toml(settings_toml); + auto context = c2pa::Context::ContextBuilder().with_toml(settings_toml).create_context(); // Create builder using context containing settings (does not generate thumbnails) auto builder_no_thumbnail = c2pa::Builder(context, manifest); @@ -909,7 +909,7 @@ TEST_F(BuilderTest, SignImageThumbnailSettingsFileToml) // Now, create builder with another context (settings generate a thumbnail) fs::path settings_path2 = current_dir / "../tests/fixtures/settings/test_settings_with_thumbnail.toml"; auto settings_toml2 = c2pa_test::read_text_file(settings_path2); - auto context2 = c2pa::Context::from_toml(settings_toml2); + auto context2 = c2pa::Context::ContextBuilder().with_toml(settings_toml2).create_context(); auto builder_with_thumbnail = c2pa::Builder(context2, manifest); std::vector manifest_data_with_thumbnail; @@ -2812,7 +2812,7 @@ TEST_F(BuilderTest, TrustHandling) // already configured with that trust to use with our Builder and Reader. fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_example.toml"; auto settings = c2pa_test::read_text_file(settings_path); - auto trusted_context = c2pa::Context::from_toml(settings); + auto trusted_context = c2pa::Context::ContextBuilder().with_toml(settings).create_context(); // Create builder using context containing settings that does generate thumbnails auto builder = c2pa::Builder(trusted_context, manifest); diff --git a/tests/context.test.cpp b/tests/context.test.cpp index 52c52913..176fe6e4 100644 --- a/tests/context.test.cpp +++ b/tests/context.test.cpp @@ -62,21 +62,12 @@ static std::string load_fixture(const std::string &name) return c2pa_test::read_text_file(fixture_path(name)); } -// Can create a context -TEST(Context, ContextCreateReturnsValid) -{ - auto context = c2pa::Context::create(); - ASSERT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); -} - // Can create a context using JSON settings TEST(Context, ContextFromJsonValid) { std::string json = R"({"settings": {}})"; auto context = c2pa::Context::from_json(json); ASSERT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); } // Context::from_json() with invalid JSON throws @@ -88,20 +79,19 @@ TEST(Context, ContextFromJsonInvalidThrows) ); } -// Context::from_toml() with valid TOML returns valid context +// ContextBuilder::with_toml() with valid TOML returns valid context TEST(Context, ContextFromTomlValid) { std::string toml = "[settings]\n"; - auto context = c2pa::Context::from_toml(toml); + auto context = c2pa::Context::ContextBuilder().with_toml(toml).create_context(); ASSERT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); } -// Context::from_toml() with invalid TOML throws +// ContextBuilder::with_toml() with invalid TOML throws TEST(Context, ContextFromTomlInvalidThrows) { EXPECT_THROW( - { auto context = c2pa::Context::from_toml("bad toml [[[]"); }, + { auto context = c2pa::Context::ContextBuilder().with_toml("bad toml [[[]").create_context(); }, c2pa::C2paException ); } @@ -135,7 +125,6 @@ TEST(Context, ContextBuilderEmptyBuild) auto context = builder.create_context(); ASSERT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); } // Helper function to check if thumbnail is present in signed manifest @@ -322,7 +311,6 @@ TEST(Context, ContextBuilderMoveConstructor) { auto context = b2.create_context(); EXPECT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); } TEST(Context, ContextBuilderMoveAssignment) { @@ -336,7 +324,6 @@ TEST(Context, ContextBuilderMoveAssignment) { auto context = b1.create_context(); EXPECT_NE(context, nullptr); - EXPECT_TRUE(context->has_context()); } TEST(Context, SettingsMoveConstructor) { diff --git a/tests/cpp-app-test/test.cpp b/tests/cpp-app-test/test.cpp index e2328e84..a306d712 100644 --- a/tests/cpp-app-test/test.cpp +++ b/tests/cpp-app-test/test.cpp @@ -188,7 +188,7 @@ int main() char *trust_settings = load_file("tests/fixtures/settings/test_settings_example.toml"); // Create a context with trust anchors - auto trusted_context = c2pa::Context::from_toml(trust_settings); + auto trusted_context = c2pa::Context::ContextBuilder().with_toml(trust_settings).create_context(); free(trust_settings); cout << "Created context with trust anchors" << endl; diff --git a/tests/reader.test.cpp b/tests/reader.test.cpp index a226a88a..785db24a 100644 --- a/tests/reader.test.cpp +++ b/tests/reader.test.cpp @@ -354,7 +354,7 @@ TEST_F(ReaderTest, ReadManifestWithTrustConfiguredTomlSettings) // already configured with that trust to use with our Builder and Reader. fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_example.toml"; auto settings = c2pa_test::read_text_file(settings_path); - auto trusted_context = c2pa::Context::from_toml(settings); + auto trusted_context = c2pa::Context::ContextBuilder().with_toml(settings).create_context(); // When reading, the Reader also needs to know about trust, to determine the manifest validation state // If there is a valid trust chain, the manifest will be in validation_state Trusted. From d5497efbe5b5b93f74eb0df691c7c0566b9d6fb9 Mon Sep 17 00:00:00 2001 From: Tania Mathern Date: Tue, 10 Feb 2026 09:26:56 -0800 Subject: [PATCH 2/3] fix: MOre toml stuffs removed --- include/c2pa.hpp | 60 +--- src/c2pa.cpp | 17 +- tests/builder.test.cpp | 92 +----- tests/context.test.cpp | 80 +---- tests/cpp-app-test/test.cpp | 6 +- .../settings/test_settings_example.toml | 292 ------------------ .../settings/test_settings_no_thumbnail.toml | 30 -- .../test_settings_with_thumbnail.toml | 30 -- tests/reader.test.cpp | 24 -- 9 files changed, 40 insertions(+), 591 deletions(-) delete mode 100644 tests/fixtures/settings/test_settings_example.toml delete mode 100644 tests/fixtures/settings/test_settings_no_thumbnail.toml delete mode 100644 tests/fixtures/settings/test_settings_with_thumbnail.toml diff --git a/include/c2pa.hpp b/include/c2pa.hpp index 0591c76f..deb9614f 100644 --- a/include/c2pa.hpp +++ b/include/c2pa.hpp @@ -80,23 +80,6 @@ namespace c2pa constexpr const char* BinaryArchive = "application/c2pa"; } - /// @brief Enum for settings/configuration format - enum class ConfigFormat { - JSON, - TOML - }; - - /// @brief Helper to convert enum to string format - /// @param format ConfigFormat enum value - /// @return Format as string, defaults to json - inline const char* config_format_to_string(ConfigFormat format) noexcept { - switch(format) { - case ConfigFormat::JSON: return "json"; - case ConfigFormat::TOML: return "toml"; - default: return "json"; - } - } - /// C2paException class for C2pa errors. /// This class is used to throw exceptions for errors encountered by the C2pa library via c2pa_error(). class C2PA_CPP_API C2paException : public std::exception @@ -157,7 +140,7 @@ namespace c2pa }; /// @brief (C2PA SDK) Settings configuration object for creating contexts. - /// @details Settings can be configured via JSON/TOML strings or programmatically + /// @details Settings can be configured via JSON strings or programmatically /// via set() and update() methods. Once passed to Context::ContextBuilder, /// the settings are copied into the context and the Settings /// object can be reused or discarded. @@ -167,18 +150,11 @@ namespace c2pa Settings(); /// @brief Create settings from a configuration string. - /// @param data Configuration data in JSON or TOML format. - /// @param format Format of the data ("json" or "toml"). + /// @param data Configuration data in JSON format. + /// @param format Format of the data ("json"). /// @throws C2paException if parsing fails. Settings(const std::string& data, const std::string& format); - /// @brief Create settings from a configuration string. - /// @param data Configuration data in ConfigFormat format. - /// @param format Format of the data from `ConfigFormat` enum. - /// @throws C2paException if parsing fails. - Settings(const std::string& data, ConfigFormat format) - : Settings(data, config_format_to_string(format)) {} - // Move semantics Settings(Settings&&) noexcept; Settings& operator=(Settings&&) noexcept; @@ -196,21 +172,19 @@ namespace c2pa /// @throws C2paException if the path or value is invalid. Settings& set(const std::string& path, const std::string& json_value); - /// @brief Merge configuration from a std::string (latest configuration wins). - /// @param data Configuration data in JSON or TOML format. - /// @param format Format of the data ("json" or "toml"). + /// @brief Merge configuration from a JSON string (latest configuration wins). + /// @param data Configuration data in JSON format. /// @return Reference to this Settings for method chaining. /// @throws C2paException if parsing fails. - Settings& update(const std::string& data, const std::string& format); + /// @note This is the recommended overload when configuration is JSON. + Settings& update(const std::string& data) { return update(data, "json"); } /// @brief Merge configuration from a std::string (latest configuration wins). - /// @param data Configuration data in ConfigFormat format. - /// @param format Format of the data as `ConfigFormat` enum. + /// @param data Configuration data in JSON or TOML format. + /// @param format Format of the data ("json" or "toml"). /// @return Reference to this Settings for method chaining. /// @throws C2paException if parsing fails. - Settings& update(const std::string& data, ConfigFormat format) { - return update(data, config_format_to_string(format)); - } + Settings& update(const std::string& data, const std::string& format); /// @brief Get the raw C FFI settings pointer. /// @return Pointer to C2paSettings, or nullptr if not initialized. @@ -259,12 +233,6 @@ namespace c2pa /// @throws C2paException if builder is invalid or JSON is invalid. ContextBuilder& with_json(const std::string& json); - /// @brief Configure settings with TOML string. - /// @param toml TOML configuration string. - /// @return Reference to this ContextBuilder for method chaining. - /// @throws C2paException if builder is invalid or TOML is invalid. - ContextBuilder& with_toml(const std::string& toml); - /// @brief Create the immutable Context (consuming build operation). /// @return Shared pointer to the new Context. /// @throws C2paException if context creation fails or builder is invalid. @@ -315,8 +283,8 @@ namespace c2pa /// @param data the std::string to load. /// @param format the mime format of the string. /// @throws a C2pa::C2paException for errors encountered by the C2PA library. - /// @deprecated Use Context::from_json() or Context::ContextBuilder().with_toml().create_context() instead for better thread safety. - [[deprecated("Use Context pattern instead, Context::from_json() or Context::ContextBuilder().with_toml().create_context() instead")]] + /// @deprecated Use Context::from_json() or Context::ContextBuilder().with_json().create_context() instead for better thread safety. + [[deprecated("Use Context pattern instead, Context::from_json() or Context::ContextBuilder().with_json().create_context() instead")]] void C2PA_CPP_API load_settings(const std::string& data, const std::string& format); /// Reads a file and returns the manifest json as a C2pa::String. @@ -746,14 +714,14 @@ namespace c2pa /// @param ingredient_json Any fields of the ingredient you want to define (e.g. title, relationship). /// @param archive The input stream to read the archive from. /// @throws C2pa::C2paException for errors encountered by the C2PA library. - void add_ingredient_from_binary_archive(const std::string &ingredient_json, std::istream &archive); + void from_ingredient_archive(const std::string &ingredient_json, std::istream &archive); /// @brief Add an archive (working store) as an ingredient to the builder. /// @param ingredient_json Any fields of the ingredient you want to define (e.g. title, relationship). /// @param archive_path The path to the archive file. /// @throws C2pa::C2paException for errors encountered by the C2PA library. /// @note Prefer using the streaming APIs if possible - void add_ingredient_from_binary_archive(const std::string &ingredient_json, const std::filesystem::path &archive_path); + void from_ingredient_archive(const std::string &ingredient_json, const std::filesystem::path &archive_path); /// @brief Add an action to the manifest the Builder is constructing. /// @param action_json JSON std::string containing the action data. diff --git a/src/c2pa.cpp b/src/c2pa.cpp index 1a99f9e7..3830c7a9 100644 --- a/src/c2pa.cpp +++ b/src/c2pa.cpp @@ -259,7 +259,7 @@ inline std::string extract_file_extension(const std::filesystem::path &path) noe return ext.empty() ? "" : ext.substr(1); } -/// @brief Only call C API free when pointer is non-null (FFI can panic on null). +/// @brief Only call C API free when pointer is non-null. inline void safe_c2pa_free(void* p) { if (p != nullptr) c2pa_free(p); @@ -457,14 +457,7 @@ inline std::vector to_byte_vector(const unsigned char* data, int6 if (!is_valid()) { throw C2paException("ContextBuilder is invalid (already consumed)"); } - return with_settings(Settings(json, ConfigFormat::JSON)); - } - - Context::ContextBuilder& Context::ContextBuilder::with_toml(const std::string& toml) { - if (!is_valid()) { - throw C2paException("ContextBuilder is invalid (already consumed)"); - } - return with_settings(Settings(toml, ConfigFormat::TOML)); + return with_settings(Settings(json, "json")); } std::shared_ptr Context::ContextBuilder::create_context() { @@ -971,15 +964,15 @@ inline std::vector to_byte_vector(const unsigned char* data, int6 add_ingredient(ingredient_json, format.c_str(), *stream); } - void Builder::add_ingredient_from_binary_archive(const std::string &ingredient_json, std::istream &archive) + void Builder::from_ingredient_archive(const std::string &ingredient_json, std::istream &archive) { add_ingredient(ingredient_json, C2paMimeType::BinaryArchive, archive); } - void Builder::add_ingredient_from_binary_archive(const std::string &ingredient_json, const std::filesystem::path &archive_path) + void Builder::from_ingredient_archive(const std::string &ingredient_json, const std::filesystem::path &archive_path) { auto stream = detail::open_file_binary(archive_path); - add_ingredient_from_binary_archive(ingredient_json, *stream); + from_ingredient_archive(ingredient_json, *stream); } void Builder::add_action(const std::string &action_json) diff --git a/tests/builder.test.cpp b/tests/builder.test.cpp index 45d74910..8192783f 100644 --- a/tests/builder.test.cpp +++ b/tests/builder.test.cpp @@ -871,72 +871,6 @@ TEST_F(BuilderTest, SignImageFileNoThumbnailAutoGen) EXPECT_TRUE(parsed_no_context["manifests"][active_manifest_value_no_context].contains("thumbnail")); }; -TEST_F(BuilderTest, SignImageThumbnailSettingsFileToml) -{ - fs::path current_dir = fs::path(__FILE__).parent_path(); - - // Construct the paths relative to the current directory - fs::path manifest_path = current_dir / "../tests/fixtures/training.json"; - fs::path certs_path = current_dir / "../tests/fixtures/es256_certs.pem"; - fs::path signed_image_path = current_dir / "../tests/fixtures/A.jpg"; - fs::path output_path_with_context = get_temp_path("image_context_settings_toml.jpg"); - fs::path output_path_no_context = get_temp_path("image_no_context_toml.jpg"); - - auto manifest = c2pa_test::read_text_file(manifest_path); - auto certs = c2pa_test::read_text_file(certs_path); - auto p_key = c2pa_test::read_text_file(current_dir / "../tests/fixtures/es256_private.key"); - - // Create a signer - c2pa::Signer signer = c2pa::Signer("Es256", certs, p_key, "http://timestamp.digicert.com"); - - // Create context with specific settings via toml, by loading the TOML file - fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_no_thumbnail.toml"; - auto settings_toml = c2pa_test::read_text_file(settings_path); - auto context = c2pa::Context::ContextBuilder().with_toml(settings_toml).create_context(); - - // Create builder using context containing settings (does not generate thumbnails) - auto builder_no_thumbnail = c2pa::Builder(context, manifest); - std::vector manifest_data_no_thumbnail; - ASSERT_NO_THROW(manifest_data_no_thumbnail = builder_no_thumbnail.sign(signed_image_path, output_path_with_context, signer)); - - // Verify the signed file with context exists and is readable - ASSERT_TRUE(std::filesystem::exists(output_path_with_context)); - auto reader_without_thumbnails = c2pa::Reader(output_path_with_context); - std::string json_without_thumbnails; - ASSERT_NO_THROW(json_without_thumbnails = reader_without_thumbnails.json()); - EXPECT_FALSE(json_without_thumbnails.empty()); - - // Now, create builder with another context (settings generate a thumbnail) - fs::path settings_path2 = current_dir / "../tests/fixtures/settings/test_settings_with_thumbnail.toml"; - auto settings_toml2 = c2pa_test::read_text_file(settings_path2); - auto context2 = c2pa::Context::ContextBuilder().with_toml(settings_toml2).create_context(); - - auto builder_with_thumbnail = c2pa::Builder(context2, manifest); - std::vector manifest_data_with_thumbnail; - ASSERT_NO_THROW(manifest_data_with_thumbnail = builder_with_thumbnail.sign(signed_image_path, output_path_no_context, signer)); - - // Verify the signed file without context exists and is readable - ASSERT_TRUE(std::filesystem::exists(output_path_no_context)); - auto reader_with_thumbnails = c2pa::Reader(output_path_no_context); - std::string json_with_thumbnails; - ASSERT_NO_THROW(json_with_thumbnails = reader_with_thumbnails.json()); - EXPECT_FALSE(json_with_thumbnails.empty()); - - // Both builders should successfully create valid manifests, - // but one should have thumbnails whereas the other shouldn't - json parsed_no_thumbnail = json::parse(json_without_thumbnails); - json parsed_with_thumbnail = json::parse(json_with_thumbnails); - - // Both should have valid structure - EXPECT_TRUE(parsed_no_thumbnail.contains("active_manifest")); - EXPECT_TRUE(parsed_with_thumbnail.contains("active_manifest")); - - std::string active_manifest_value_context = parsed_no_thumbnail["active_manifest"]; - EXPECT_FALSE(parsed_no_thumbnail["manifests"][active_manifest_value_context].contains("thumbnail")); - std::string active_manifest_value_no_context = parsed_with_thumbnail["active_manifest"]; - EXPECT_TRUE(parsed_with_thumbnail["manifests"][active_manifest_value_no_context].contains("thumbnail")); -}; - TEST_F(BuilderTest, SignImageThumbnailSettingsFileJson) { fs::path current_dir = fs::path(__FILE__).parent_path(); @@ -1078,7 +1012,7 @@ TEST_F(BuilderTest, SignImageThumbnailSettingsIncrementalObject) } } })"; - settings.update(updated_config, c2pa::ConfigFormat::JSON); + settings.update(updated_config, "json"); // Build context from Settings object we just did auto context = c2pa::Context::ContextBuilder() @@ -2810,9 +2744,9 @@ TEST_F(BuilderTest, TrustHandling) // Trust is based on a chain of trusted certificates. When signing, we may need to know // if the ingredients are trusted at time of signing, so we benefit from having a context // already configured with that trust to use with our Builder and Reader. - fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_example.toml"; + fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_example.json"; auto settings = c2pa_test::read_text_file(settings_path); - auto trusted_context = c2pa::Context::ContextBuilder().with_toml(settings).create_context(); + auto trusted_context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings(settings, "json")).create_context(); // Create builder using context containing settings that does generate thumbnails auto builder = c2pa::Builder(trusted_context, manifest); @@ -3257,7 +3191,7 @@ TEST_F(BuilderTest, MultipleArchivesAsIngredients) << "Third ingredient should have componentOf relationship"; } -// Test add_ingredient_from_binary_archive with stream overload +// Test from_ingredient_archive with stream overload TEST_F(BuilderTest, AddIngredientFromArchiveStream) { auto manifest = c2pa_test::read_text_file(c2pa_test::get_fixture_path("training.json")); @@ -3281,7 +3215,7 @@ TEST_F(BuilderTest, AddIngredientFromArchiveStream) std::string ingredient_json = R"({"title": "Archive Ingredient", "relationship": "parentOf"})"; EXPECT_NO_THROW({ - final_builder.add_ingredient_from_binary_archive(ingredient_json, archive_stream); + final_builder.from_ingredient_archive(ingredient_json, archive_stream); }); // Reset settings @@ -3312,7 +3246,7 @@ TEST_F(BuilderTest, AddIngredientFromArchiveStream) EXPECT_EQ(ingredients[0]["relationship"], "parentOf"); } -// Test add_ingredient_from_binary_archive with file overload +// Test from_ingredient_archive with file overload TEST_F(BuilderTest, AddIngredientFromArchiveFile) { auto manifest = c2pa_test::read_text_file(c2pa_test::get_fixture_path("training.json")); @@ -3335,7 +3269,7 @@ TEST_F(BuilderTest, AddIngredientFromArchiveFile) std::string ingredient_json = R"({"title": "File Archive Ingredient", "relationship": "componentOf"})"; EXPECT_NO_THROW({ - final_builder.add_ingredient_from_binary_archive(ingredient_json, archive_path); + final_builder.from_ingredient_archive(ingredient_json, archive_path); }); // Reset settings @@ -3364,7 +3298,7 @@ TEST_F(BuilderTest, AddIngredientFromArchiveFile) EXPECT_EQ(ingredients[0]["relationship"], "componentOf"); } -// Test add_ingredient_from_binary_archive with multiple archives +// Test from_ingredient_archive with multiple archives TEST_F(BuilderTest, AddMultipleArchivesFromArchive) { auto manifest = c2pa_test::read_text_file(c2pa_test::get_fixture_path("training.json")); @@ -3405,19 +3339,19 @@ TEST_F(BuilderTest, AddMultipleArchivesFromArchive) archive1_stream.seekg(0); std::string ingredient1_json = R"({"title": "Archive 1 New API", "relationship": "parentOf"})"; EXPECT_NO_THROW({ - final_builder.add_ingredient_from_binary_archive(ingredient1_json, archive1_stream); + final_builder.from_ingredient_archive(ingredient1_json, archive1_stream); }); archive2_stream.seekg(0); std::string ingredient2_json = R"({"title": "Archive 2 New API", "relationship": "componentOf"})"; EXPECT_NO_THROW({ - final_builder.add_ingredient_from_binary_archive(ingredient2_json, archive2_stream); + final_builder.from_ingredient_archive(ingredient2_json, archive2_stream); }); archive3_stream.seekg(0); std::string ingredient3_json = R"({"title": "Archive 3 New API", "relationship": "componentOf"})"; EXPECT_NO_THROW({ - final_builder.add_ingredient_from_binary_archive(ingredient3_json, archive3_stream); + final_builder.from_ingredient_archive(ingredient3_json, archive3_stream); }); // Reset settings @@ -3460,7 +3394,7 @@ TEST_F(BuilderTest, AddMultipleArchivesFromArchive) << "Third ingredient should have componentOf relationship"; } -// Test add_ingredient_from_binary_archive with invalid archive +// Test from_ingredient_archive with invalid archive TEST_F(BuilderTest, AddIngredientFromArchiveInvalidStream) { auto manifest = c2pa_test::read_text_file(c2pa_test::get_fixture_path("training.json")); @@ -3475,7 +3409,7 @@ TEST_F(BuilderTest, AddIngredientFromArchiveInvalidStream) // Should throw C2paException when trying to add invalid archive EXPECT_THROW({ - builder.add_ingredient_from_binary_archive(ingredient_json, invalid_stream); + builder.from_ingredient_archive(ingredient_json, invalid_stream); }, c2pa::C2paException); } diff --git a/tests/context.test.cpp b/tests/context.test.cpp index 176fe6e4..54251391 100644 --- a/tests/context.test.cpp +++ b/tests/context.test.cpp @@ -79,19 +79,19 @@ TEST(Context, ContextFromJsonInvalidThrows) ); } -// ContextBuilder::with_toml() with valid TOML returns valid context +// ContextBuilder::with_settings(Settings(..., "toml")) with valid TOML returns valid context TEST(Context, ContextFromTomlValid) { std::string toml = "[settings]\n"; - auto context = c2pa::Context::ContextBuilder().with_toml(toml).create_context(); + auto context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings(toml, "toml")).create_context(); ASSERT_NE(context, nullptr); } -// ContextBuilder::with_toml() with invalid TOML throws +// ContextBuilder::with_settings(Settings(..., "toml")) with invalid TOML throws TEST(Context, ContextFromTomlInvalidThrows) { EXPECT_THROW( - { auto context = c2pa::Context::ContextBuilder().with_toml("bad toml [[[]").create_context(); }, + { auto context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings("bad toml [[[]", "toml")).create_context(); }, c2pa::C2paException ); } @@ -175,7 +175,7 @@ TEST_F(ContextTest, UpdateOverridesSetJson) { c2pa::Settings settings; settings.set("builder.thumbnail.enabled", "true"); - settings.update(settings_json, c2pa::ConfigFormat::JSON); + settings.update(settings_json, "json"); auto context = c2pa::Context::ContextBuilder().with_settings(settings).create_context(); auto manifest_json = sign_with_context(context, get_temp_path("update_overrides_set_json.jpg")); @@ -198,76 +198,6 @@ TEST_F(ContextTest, SetOverridesUpdateJson) { EXPECT_TRUE(has_thumbnail(manifest_json)); } -TEST_F(ContextTest, UpdateTomlThenUpdateJson) { - fs::path current_dir = fs::path(__FILE__).parent_path(); - fs::path toml_path = current_dir / "fixtures/settings/test_settings_with_thumbnail.toml"; - fs::path json_path = current_dir / "fixtures/settings/test_settings_no_thumbnail.json"; - - auto settings_toml = c2pa_test::read_text_file(toml_path); - auto settings_json = c2pa_test::read_text_file(json_path); - - c2pa::Settings settings; - settings.update(settings_toml, c2pa::ConfigFormat::TOML); - settings.update(settings_json, c2pa::ConfigFormat::JSON); - - auto context = c2pa::Context::ContextBuilder().with_settings(settings).create_context(); - auto manifest_json = sign_with_context(context, get_temp_path("update_toml_then_json.jpg")); - - EXPECT_FALSE(has_thumbnail(manifest_json)); -} - -TEST_F(ContextTest, UpdateJsonThenUpdateToml) { - fs::path current_dir = fs::path(__FILE__).parent_path(); - fs::path json_path = current_dir / "fixtures/settings/test_settings_no_thumbnail.json"; - fs::path toml_path = current_dir / "fixtures/settings/test_settings_with_thumbnail.toml"; - - auto settings_json = c2pa_test::read_text_file(json_path); - auto settings_toml = c2pa_test::read_text_file(toml_path); - - c2pa::Settings settings; - settings.update(settings_json, "json"); - settings.update(settings_toml, "toml"); - - auto context = c2pa::Context::ContextBuilder().with_settings(settings).create_context(); - auto manifest_json = sign_with_context(context, get_temp_path("update_json_then_toml.jpg")); - - EXPECT_TRUE(has_thumbnail(manifest_json)); -} - -TEST_F(ContextTest, WithJsonThenWithToml) { - fs::path current_dir = fs::path(__FILE__).parent_path(); - fs::path json_path = current_dir / "fixtures/settings/test_settings_with_thumbnail.json"; - fs::path toml_path = current_dir / "fixtures/settings/test_settings_no_thumbnail.toml"; - - auto settings_json = c2pa_test::read_text_file(json_path); - auto settings_toml = c2pa_test::read_text_file(toml_path); - - auto context = c2pa::Context::ContextBuilder() - .with_json(settings_json) - .with_toml(settings_toml) - .create_context(); - - auto manifest_json = sign_with_context(context, get_temp_path("with_json_then_toml.jpg")); - EXPECT_FALSE(has_thumbnail(manifest_json)); -} - -TEST_F(ContextTest, WithTomlThenWithJson) { - fs::path current_dir = fs::path(__FILE__).parent_path(); - fs::path toml_path = current_dir / "fixtures/settings/test_settings_no_thumbnail.toml"; - fs::path json_path = current_dir / "fixtures/settings/test_settings_with_thumbnail.json"; - - auto settings_toml = c2pa_test::read_text_file(toml_path); - auto settings_json = c2pa_test::read_text_file(json_path); - - auto context = c2pa::Context::ContextBuilder() - .with_toml(settings_toml) - .with_json(settings_json) - .create_context(); - - auto manifest_json = sign_with_context(context, get_temp_path("with_toml_then_json.jpg")); - EXPECT_TRUE(has_thumbnail(manifest_json)); -} - TEST_F(ContextTest, WithSettingsThenWithJson) { fs::path current_dir = fs::path(__FILE__).parent_path(); fs::path json_path = current_dir / "fixtures/settings/test_settings_no_thumbnail.json"; diff --git a/tests/cpp-app-test/test.cpp b/tests/cpp-app-test/test.cpp index a306d712..c664fe94 100644 --- a/tests/cpp-app-test/test.cpp +++ b/tests/cpp-app-test/test.cpp @@ -184,11 +184,11 @@ int main() cout << "\n--- Example 4: Trust-based validation ---" << endl; try { - // Load trust configuration from TOML file - char *trust_settings = load_file("tests/fixtures/settings/test_settings_example.toml"); + // Load trust configuration from config file + char *trust_settings = load_file("tests/fixtures/settings/test_settings_example.json"); // Create a context with trust anchors - auto trusted_context = c2pa::Context::ContextBuilder().with_toml(trust_settings).create_context(); + auto trusted_context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings(trust_settings, "json")).create_context(); free(trust_settings); cout << "Created context with trust anchors" << endl; diff --git a/tests/fixtures/settings/test_settings_example.toml b/tests/fixtures/settings/test_settings_example.toml deleted file mode 100644 index 17ca43a6..00000000 --- a/tests/fixtures/settings/test_settings_example.toml +++ /dev/null @@ -1,292 +0,0 @@ -# C2PA SDK example configuration file (settings) sample - -# Version information. -version = 1 - -# Trust settings for certificate validation. -# [trust] -# String to user-provided trust anchors (PEM format). -# user_anchors = "" -# String to system trust anchors (PEM format). -# trust_anchors = "" -[trust] -trust_anchors = """-----BEGIN CERTIFICATE----- -MIICEzCCAcWgAwIBAgIUW4fUnS38162x10PCnB8qFsrQuZgwBQYDK2VwMHcxCzAJ -BgNVBAYTAlVTMQswCQYDVQQIDAJDQTESMBAGA1UEBwwJU29tZXdoZXJlMRowGAYD -VQQKDBFDMlBBIFRlc3QgUm9vdCBDQTEZMBcGA1UECwwQRk9SIFRFU1RJTkdfT05M -WTEQMA4GA1UEAwwHUm9vdCBDQTAeFw0yMjA2MTAxODQ2NDFaFw0zMjA2MDcxODQ2 -NDFaMHcxCzAJBgNVBAYTAlVTMQswCQYDVQQIDAJDQTESMBAGA1UEBwwJU29tZXdo -ZXJlMRowGAYDVQQKDBFDMlBBIFRlc3QgUm9vdCBDQTEZMBcGA1UECwwQRk9SIFRF -U1RJTkdfT05MWTEQMA4GA1UEAwwHUm9vdCBDQTAqMAUGAytlcAMhAGPUgK9q1H3D -eKMGqLGjTXJSpsrLpe0kpxkaFMe7KUAuo2MwYTAdBgNVHQ4EFgQUXuZWArP1jiRM -fgye6ZqRyGupTowwHwYDVR0jBBgwFoAUXuZWArP1jiRMfgye6ZqRyGupTowwDwYD -VR0TAQH/BAUwAwEB/zAOB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5rpAULDxVSrN34A7BlsaXYQLnSkLMqva6E7nq2JBYjkqf -iwNQm1DDcQPtPTnddOs= ------END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIICkTCCAhagAwIBAgIUIngKvNC/BMF3TRIafgweprIbGgAwCgYIKoZIzj0EAwMw -dzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQHDAlTb21ld2hlcmUx -GjAYBgNVBAoMEUMyUEEgVGVzdCBSb290IENBMRkwFwYDVQQLDBBGT1IgVEVTVElO -R19PTkxZMRAwDgYDVQQDDAdSb290IENBMB4XDTIyMDYxMDE4NDY0MFoXDTMyMDYw -NzE4NDY0MFowdzELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMRIwEAYDVQQHDAlT -b21ld2hlcmUxGjAYBgNVBAoMEUMyUEEgVGVzdCBSb290IENBMRkwFwYDVQQLDBBG -T1IgVEVTVElOR19PTkxZMRAwDgYDVQQDDAdSb290IENBMHYwEAYHKoZIzj0CAQYF -K4EEACIDYgAEX3FzSTnCcEAP3wteNaiy4GZzZ+ABd2Y7gJpfyZf3kkCuX/I3psFq -QBRvb3/FEBaDT4VbDNlZ0WLwtw5d3PI42Zufgpxemgfjf31d8H51eU3/IfAz5AFX -y/OarhObHgVvo2MwYTAdBgNVHQ4EFgQUe+FK5t6/bQGIcGY6kkeIKTX/bJ0wHwYD -VR0jBBgwFoAUe+FK5t6/bQGIcGY6kkeIKTX/bJ0wDwYDVR0TAQH/BAUwAwEB/zAO -BgNVHQ8BAf8EBAMCAYYwCgYIKoZIzj0EAwMDaQAwZgIxAPOgmJbVdhDh9KlgQXqE -FzHiCt347JG4strk22MXzOgxQ0LnXStIh+viC3S1INzuBgIxAI1jiUBX/V7Gg0y6 -Y/p6a63Xp2w+ia7vlUaUBWsR3ex9NNSTPLNoDkoTCSDOE2O20w== ------END CERTIFICATE----- ------BEGIN CERTIFICATE----- -MIICUzCCAfmgAwIBAgIUdmkq4byvgk2FSnddHqB2y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sAA5LtFl8xeVgt -xPd7wFhjRZHfuWb2cs63xjAGjQ== ------END CERTIFICATE----- -""" -# String to trust configuration. -trust_config = """ -//id-kp-emailProtection -1.3.6.1.5.5.7.3.4 -//id-kp-documentSigning -1.3.6.1.5.5.7.3.36 -//id-kp-timeStamping -1.3.6.1.5.5.7.3.8 -//id-kp-OCSPSigning -1.3.6.1.5.5.7.3.9 -// MS C2PA Signing -1.3.6.1.4.1.311.76.59.1.9 -// c2pa-kp-claimSigning -1.3.6.1.4.1.62558.2.1 -""" - -# # Path to allowed certificate list (PEM format). -# allowed_list = "" - -# Verification settings. -[verify] -# Verify manifests after reading. -verify_after_reading = true -# Verify manifests after signing. -verify_after_sign = true -# Fetch remote manifests. -remote_manifest_fetch = true - -# Configuration for the `Builder`. -[builder] -intent = "edit" - -# Claim generator info list. -[builder.claim_generator_info] -# A human readable name. -name = "c2pa-cpp testing" -# A human readable string of the product's version. -version = "0.1.0" -# The operating system the claim generator is running on. -#operating_system.name = "macOS" -# Or specify "auto" to infer the operating system automatically. -operating_system = "auto" - -# Actions assertion configuration. -[builder.actions] -# Signifies if all the actions that ever happened on a particular asset are specified -# or if some are missing. -#all_actions_included = true - -# Settings for automatic thumbnail generation. -[builder.thumbnail] -# Whether to enable automatic thumbnail generation. -enabled = true -# Whether to ignore errors when generating a thumbnail and continue signing. -ignore_errors = true -# The size of the longest edge of the thumbnail. -long_edge = 512 -# The output format of the thumbnail. -# -# If this field isn't specified, the thumbnail format will correspond to the -# input format. -#format = "png" -# Whether or not to prefer a smaller sized media format for the thumbnail. -# -# The "format" option takes precedence over this field. -# -# For instance, if the source input type is a PNG, but it doesn't have an alpha channel, -# the image will be converted to a JPEG of smaller size. -prefer_smallest_format = true -# The output quality of the thumbnail (low, medium, high). -quality = "medium" diff --git a/tests/fixtures/settings/test_settings_no_thumbnail.toml b/tests/fixtures/settings/test_settings_no_thumbnail.toml deleted file mode 100644 index 63e54b45..00000000 --- a/tests/fixtures/settings/test_settings_no_thumbnail.toml +++ /dev/null @@ -1,30 +0,0 @@ -# C2PA SDK example configuration file to -# disable automatic thumbnail generation - -# Version information. -version = 1 - -# Settings for automatic thumbnail generation. -[builder.thumbnail] -# Whether to enable automatic thumbnail generation. -enabled = false - -# Once thumbnails are disabled, all the other settings become obsolete -# Whether to ignore errors when generating a thumbnail and continue signing. -#ignore_errors = true -# The size of the longest edge of the thumbnail. -#long_edge = 512 -# The output format of the thumbnail. -# -# If this field isn't specified, the thumbnail format will correspond to the -# input format. -#format = "png" -# Whether or not to prefer a smaller sized media format for the thumbnail. -# -# The "format" option takes precedence over this field. -# -# For instance, if the source input type is a PNG, but it doesn't have an alpha channel, -# the image will be converted to a JPEG of smaller size. -#prefer_smallest_format = true -# The output quality of the thumbnail (low, medium, high). -#quality = "medium" diff --git a/tests/fixtures/settings/test_settings_with_thumbnail.toml b/tests/fixtures/settings/test_settings_with_thumbnail.toml deleted file mode 100644 index 078f5711..00000000 --- a/tests/fixtures/settings/test_settings_with_thumbnail.toml +++ /dev/null @@ -1,30 +0,0 @@ -# C2PA SDK example configuration file to -# enable automatic thumbnail generation - -# Version information. -version = 1 - -# Settings for automatic thumbnail generation. -[builder.thumbnail] -# Whether to enable automatic thumbnail generation. -enabled = true - -# Once thumbnails are enabled, all the other settings gain semantic meaning too -# Whether to ignore errors when generating a thumbnail and continue signing. -ignore_errors = true -# The size of the longest edge of the thumbnail. -long_edge = 512 -# The output format of the thumbnail. -# -# If this field isn't specified, the thumbnail format will correspond to the -# input format. -#format = "png" -# Whether or not to prefer a smaller sized media format for the thumbnail. -# -# The "format" option takes precedence over this field. -# -# For instance, if the source input type is a PNG, but it doesn't have an alpha channel, -# the image will be converted to a JPEG of smaller size. -prefer_smallest_format = true -# The output quality of the thumbnail (low, medium, high). -quality = "medium" diff --git a/tests/reader.test.cpp b/tests/reader.test.cpp index 785db24a..31f2fdbc 100644 --- a/tests/reader.test.cpp +++ b/tests/reader.test.cpp @@ -344,30 +344,6 @@ TEST_F(ReaderTest, StreamClosed) }, c2pa::C2paException); }; -TEST_F(ReaderTest, ReadManifestWithTrustConfiguredTomlSettings) -{ - fs::path current_dir = fs::path(__FILE__).parent_path(); - fs::path signed_image_path = current_dir / "../tests/fixtures/for_trusted_read.jpg"; - - // Trust is based on a chain of trusted certificates. When signing, we may need to know - // if the ingredients are trusted at time of signing, so we benefit from having a context - // already configured with that trust to use with our Builder and Reader. - fs::path settings_path = current_dir / "../tests/fixtures/settings/test_settings_example.toml"; - auto settings = c2pa_test::read_text_file(settings_path); - auto trusted_context = c2pa::Context::ContextBuilder().with_toml(settings).create_context(); - - // When reading, the Reader also needs to know about trust, to determine the manifest validation state - // If there is a valid trust chain, the manifest will be in validation_state Trusted. - auto reader = c2pa::Reader(trusted_context, signed_image_path); - std::string read_json_manifest; - ASSERT_NO_THROW(read_json_manifest = reader.json()); - ASSERT_FALSE(read_json_manifest.empty()); - - json parsed_manifest_json = json::parse(read_json_manifest); - - ASSERT_TRUE(parsed_manifest_json["validation_state"] == "Trusted"); -} - TEST_F(ReaderTest, ReadManifestWithTrustConfiguredJsonSettings) { fs::path current_dir = fs::path(__FILE__).parent_path(); From d8ae46cd6f42f2301cae7705eeab086c9064fe05 Mon Sep 17 00:00:00 2001 From: tmathern <60901087+tmathern@users.noreply.github.com> Date: Tue, 10 Feb 2026 09:30:50 -0800 Subject: [PATCH 3/3] Update context.test.cpp --- tests/context.test.cpp | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/context.test.cpp b/tests/context.test.cpp index 54251391..841dc838 100644 --- a/tests/context.test.cpp +++ b/tests/context.test.cpp @@ -79,23 +79,6 @@ TEST(Context, ContextFromJsonInvalidThrows) ); } -// ContextBuilder::with_settings(Settings(..., "toml")) with valid TOML returns valid context -TEST(Context, ContextFromTomlValid) -{ - std::string toml = "[settings]\n"; - auto context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings(toml, "toml")).create_context(); - ASSERT_NE(context, nullptr); -} - -// ContextBuilder::with_settings(Settings(..., "toml")) with invalid TOML throws -TEST(Context, ContextFromTomlInvalidThrows) -{ - EXPECT_THROW( - { auto context = c2pa::Context::ContextBuilder().with_settings(c2pa::Settings("bad toml [[[]", "toml")).create_context(); }, - c2pa::C2paException - ); -} - // Default context can be used with a Builder TEST(Context, SettingsDefaultConstruction) {