Skip to content

Commit 5e05818

Browse files
committed
fix: crJson bindings
1 parent 6742753 commit 5e05818

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

include/c2pa.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,14 @@ namespace c2pa
935935
/// @throws C2paException for errors encountered by the C2PA library.
936936
std::string detailed_json() const;
937937

938+
/// @brief Get the manifest store as a pretty-printed crJSON string.
939+
/// @details crJSON is a standardized JSON format for C2PA manifest data.
940+
/// This call is yields valid empty JSON ("{}") if there are not
941+
/// Content Credentials to show.
942+
/// @return The manifest store as a crJSON string.
943+
/// @throws C2paException if the underlying C call returns null.
944+
std::string crjson() const;
945+
938946
/// @brief Get a resource from the reader and write it to a file.
939947
/// @param uri The URI of the resource.
940948
/// @param path The file path to write the resource to.

src/c2pa_reader.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ namespace c2pa
167167
return detail::c_string_to_string(c2pa_reader_detailed_json(c2pa_reader));
168168
}
169169

170+
std::string Reader::crjson() const
171+
{
172+
return detail::c_string_to_string(c2pa_reader_crjson(c2pa_reader));
173+
}
174+
170175
[[nodiscard]] std::optional<std::string> Reader::remote_url() const {
171176
auto url = c2pa_reader_remote_url(c2pa_reader);
172177
if (url == nullptr) { return std::nullopt; }

tests/reader.test.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,3 +694,29 @@ TEST_F(ReaderTest, ReadArchive)
694694
EXPECT_TRUE(active_manifest.contains("ingredients"));
695695
EXPECT_EQ(active_manifest["ingredients"].size(), 2);
696696
}
697+
698+
TEST_F(ReaderTest, ReaderCrJson)
699+
{
700+
fs::path current_dir = fs::path(__FILE__).parent_path();
701+
fs::path test_file = current_dir / "../tests/fixtures/cloud.jpg";
702+
ASSERT_TRUE(std::filesystem::exists(test_file)) << "Test file does not exist: " << test_file;
703+
704+
auto reader = c2pa::Reader(test_file);
705+
auto crjson = reader.crjson();
706+
EXPECT_FALSE(crjson.empty());
707+
}
708+
709+
TEST_F(ReaderTest, ReaderCrJsonSpecialChars)
710+
{
711+
auto current_dir = fs::path(__FILE__).parent_path();
712+
#ifdef _WIN32
713+
auto test_file = current_dir.parent_path() / "tests" / "fixtures" / L"CÖÄ_.jpg";
714+
#else
715+
auto test_file = current_dir.parent_path() / "tests" / "fixtures" / "CÖÄ_.jpg";
716+
#endif
717+
ASSERT_TRUE(std::filesystem::exists(test_file)) << "Test file does not exist: " << test_file;
718+
719+
auto reader = c2pa::Reader(test_file);
720+
auto crjson = reader.crjson();
721+
EXPECT_FALSE(crjson.empty());
722+
}

0 commit comments

Comments
 (0)