Skip to content

Commit cb64e8d

Browse files
committed
More example code
1 parent 6774774 commit cb64e8d

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

docs/tasks/get-resources.mdx

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,6 @@ except Exception as err:
108108
This is how to get resources from a manifest using C++.
109109
110110
```cpp
111-
fs::path manifest_path = current_dir / "../tests/fixtures/training.json";
112-
//fs::path certs_path = current_dir / "../tests/fixtures/es256_certs.pem";
113-
//fs::path image_path = current_dir / "../tests/fixtures/A.jpg";
114-
fs::path output_path = current_dir / "../target/example/training.jpg";
115-
fs::path thumbnail_path = current_dir / "../target/example/thumbnail.jpg";
116-
117111
string read_text_file(const fs::path &path)
118112
{
119113
ifstream file(path);
@@ -126,53 +120,62 @@ string read_text_file(const fs::path &path)
126120
return contents.data();
127121
}
128122
129-
try
130-
{
131-
// load the manifest, certs, and private key
132-
/* Commenting out, because not part of resource reading
133-
string manifest_json = read_text_file(manifest_path).data();
134-
135-
string certs = read_text_file(certs_path).data();
136-
137-
// create a signer
138-
Signer signer = Signer(&test_signer, Es256, certs, "http://timestamp.digicert.com");
139-
140-
auto builder = Builder(manifest_json);
141-
auto manifest_data = builder.sign(image_path, output_path, signer);
142-
*/
143-
144-
// read the new manifest and display the JSON
145-
auto reader = Reader(output_path);
146-
147-
auto manifest_store_json = reader.json();
148-
cout << "The new manifest is " << manifest_store_json << endl;
149-
150-
// get the active manifest
151-
json manifest_store = json::parse(manifest_store_json);
152-
if (manifest_store.contains("active_manifest"))
153-
{
154-
string active_manifest = manifest_store["active_manifest"];
155-
json &manifest = manifest_store["manifests"][active_manifest];
156-
157-
string identifer = manifest["thumbnail"]["identifier"];
158-
159-
reader.get_resource(identifer, thumbnail_path);
160-
161-
cout << "thumbnail written to" << thumbnail_path << endl;
162-
}
163-
}
164-
catch (c2pa::Exception const &e)
165-
{
166-
cout << "C2PA Error: " << e.what() << endl;
167-
}
168-
catch (runtime_error const &e)
169-
{
170-
cout << "setup error" << e.what() << endl;
171-
}
172-
catch (json::parse_error const &e)
173-
{
174-
cout << "parse error " << e.what() << endl;
175-
}
123+
int main()
124+
{
125+
fs::path manifest_path = current_dir / "../tests/fixtures/training.json";
126+
//fs::path certs_path = current_dir / "../tests/fixtures/es256_certs.pem";
127+
//fs::path image_path = current_dir / "../tests/fixtures/A.jpg";
128+
fs::path output_path = current_dir / "../target/example/training.jpg";
129+
fs::path thumbnail_path = current_dir / "../target/example/thumbnail.jpg";
130+
131+
try
132+
{
133+
// load the manifest, certs, and private key
134+
/* Commenting out, because not part of resource reading
135+
string manifest_json = read_text_file(manifest_path).data();
136+
137+
string certs = read_text_file(certs_path).data();
138+
139+
// create a signer
140+
Signer signer = Signer(&test_signer, Es256, certs, "http://timestamp.digicert.com");
141+
142+
auto builder = Builder(manifest_json);
143+
auto manifest_data = builder.sign(image_path, output_path, signer);
144+
*/
145+
146+
// read the new manifest and display the JSON
147+
auto reader = Reader(output_path);
148+
149+
auto manifest_store_json = reader.json();
150+
cout << "The new manifest is " << manifest_store_json << endl;
151+
152+
// get the active manifest
153+
json manifest_store = json::parse(manifest_store_json);
154+
if (manifest_store.contains("active_manifest"))
155+
{
156+
string active_manifest = manifest_store["active_manifest"];
157+
json &manifest = manifest_store["manifests"][active_manifest];
158+
159+
string identifer = manifest["thumbnail"]["identifier"];
160+
161+
reader.get_resource(identifer, thumbnail_path);
162+
163+
cout << "thumbnail written to" << thumbnail_path << endl;
164+
}
165+
}
166+
catch (c2pa::Exception const &e)
167+
{
168+
cout << "C2PA Error: " << e.what() << endl;
169+
}
170+
catch (runtime_error const &e)
171+
{
172+
cout << "setup error" << e.what() << endl;
173+
}
174+
catch (json::parse_error const &e)
175+
{
176+
cout << "parse error " << e.what() << endl;
177+
}
178+
}
176179
```
177180
178181
</TabItem>

docs/tasks/read.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ async function read(path, mimeType) {
7878
} else {
7979
console.log('No claim found');
8080
}
81+
// If there are no validation errors, then validation_status will be an empty array
8182
}
8283

8384
await read('my-c2pa-file.jpg', 'image/jpeg');

0 commit comments

Comments
 (0)