Skip to content

Commit c24e3f3

Browse files
committed
Remove setup page and include that code in each example instead
1 parent 44d3f61 commit c24e3f3

13 files changed

+199
-46
lines changed

docs/tasks/includes/_cpp-build.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
11
This is an example of how to assign a manifest to an asset and sign the claim using C++:
22

33
```cpp
4+
#include <iostream>
5+
#include <fstream>
6+
#include <string>
7+
#include <vector>
8+
#include <stdexcept>
9+
#include <openssl/evp.h>
10+
#include <openssl/pem.h>
11+
#include <openssl/err.h>
12+
#include "c2pa.hpp"
13+
#include "test_signer.hpp"
14+
15+
using namespace std;
16+
namespace fs = std::filesystem;
17+
using namespace c2pa;
18+
419
const std::string manifest_json = R"{
520
"claim_generator": "c2pa_c_test/0.1",
621
"claim_generator_info": [
722
{
8-
"name": "c2pa-c test",
23+
"name": "c2pa-c example",
924
"version": "0.1"
1025
}
1126
],
1227
"assertions": [
1328
{
14-
"label": "c2pa.training-mining",
29+
"label": "cawg.training-mining",
1530
"data": {
1631
"entries": {
17-
"c2pa.ai_generative_training": { "use": "notAllowed" },
18-
"c2pa.ai_inference": { "use": "notAllowed" },
19-
"c2pa.ai_training": { "use": "notAllowed" },
20-
"c2pa.data_mining": { "use": "notAllowed" }
32+
"cawg.ai_generative_training": { "use": "notAllowed" },
33+
"cawg.ai_inference": { "use": "notAllowed" },
34+
"cawg.ai_training": { "use": "notAllowed" },
35+
"cawg.data_mining": { "use": "notAllowed" }
2136
}
2237
}
2338
}
2439
]
2540
};
2641

2742
auto builder = Builder(manifest_json);
28-
2943
```

docs/tasks/includes/_cpp-get-resources.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
This is how to get resources from a manifest using C++.
22

33
```cpp
4+
#include <iostream>
5+
#include <fstream>
6+
#include <string>
7+
#include <vector>
8+
#include <stdexcept>
9+
#include <openssl/evp.h>
10+
#include <openssl/pem.h>
11+
#include <openssl/err.h>
12+
#include "c2pa.hpp"
13+
#include "test_signer.hpp"
14+
#include <nlohmann/json.hpp>
15+
16+
// this example uses nlohmann json for parsing the manifest
17+
using json = nlohmann::json;
18+
using namespace std;
19+
namespace fs = std::filesystem;
20+
using namespace c2pa;
21+
422
string read_text_file(const fs::path &path)
523
{
624
ifstream file(path);
@@ -23,19 +41,6 @@ int main()
2341

2442
try
2543
{
26-
// load the manifest, certs, and private key
27-
/* Commenting out, because not part of resource reading
28-
string manifest_json = read_text_file(manifest_path).data();
29-
30-
string certs = read_text_file(certs_path).data();
31-
32-
// create a signer
33-
Signer signer = Signer(&test_signer, Es256, certs, "http://timestamp.digicert.com");
34-
35-
auto builder = Builder(manifest_json);
36-
auto manifest_data = builder.sign(image_path, output_path, signer);
37-
*/
38-
3944
// read the new manifest and display the JSON
4045
auto reader = Reader(output_path);
4146

@@ -56,14 +61,17 @@ int main()
5661
cout << "thumbnail written to" << thumbnail_path << endl;
5762
}
5863
}
64+
5965
catch (c2pa::Exception const &e)
6066
{
6167
cout << "C2PA Error: " << e.what() << endl;
6268
}
69+
6370
catch (runtime_error const &e)
6471
{
6572
cout << "setup error" << e.what() << endl;
6673
}
74+
6775
catch (json::parse_error const &e)
6876
{
6977
cout << "parse error " << e.what() << endl;

docs/tasks/includes/_cpp-read.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@
22
Use the `read_file` function to read C2PA data from the specified file. This function examines the specified asset file for C2PA data and returns a JSON report if it finds any; it throws exceptions on errors. If there are validation errors, the report includes a `validation_status` field.
33

44
```cpp
5-
auto json_store = C2pa::read_file("<ASSET_FILE>", "<DATA_DIR>")
6-
```
5+
#include <iostream>
6+
#include <fstream>
7+
#include <string>
8+
#include <vector>
9+
#include <stdexcept>
10+
#include <openssl/evp.h>
11+
#include <openssl/pem.h>
12+
#include <openssl/err.h>
13+
#include "c2pa.hpp"
14+
#include "test_signer.hpp"
715

8-
Where:
16+
using namespace std;
17+
namespace fs = std::filesystem;
18+
using namespace c2pa;
919

10-
- `<ASSET_FILE>`- The asset file to read.
11-
- `<DATA_DIR>` - Optional path to data output directory; If provided, the function extracts any binary resources, such as thumbnails, icons, and C2PA data into that directory. These files are referenced by the identifier fields in the manifest store report.
20+
auto json_store = C2pa::read_file("work/media_file.jpg", "output/data_dir")
21+
```
1222
13-
For example:
23+
Where:
1424
15-
```cpp
16-
auto json_store = C2pa::read_file("work/media_file.jpg", "output/data_dir")
17-
```
25+
- `work/media_file.jpg` is the asset file to read.
26+
- `output/data_dir` is the optional path to data output directory; If provided, the function extracts any binary resources, such as thumbnails, icons, and C2PA data into that directory. These files are referenced by the identifier fields in the manifest store report.

docs/tasks/includes/_js-get-resources.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ That JavaScript library is being extensively revised so the APIs used here may c
55
The example below shows how to get resources from manifest data using the JavaScript library.
66

77
```js
8+
const version = '0.27.1';
9+
const sampleImage = 'my_image.jpg'
10+
811
import { createC2pa, selectProducer } from 'c2pa';
912
import wasmSrc from 'c2pa/dist/assets/wasm/toolkit_bg.wasm?url';
1013
import workerSrc from 'c2pa/dist/c2pa.worker.js?url';
1114
import { parseISO } from 'date-fns';
12-
13-
const sampleImage =
14-
'https://raw.githubusercontent.com/contentauth/c2pa-js/main/tools/testing/fixtures/images/CAICAI.jpg';
15+
import { createC2pa } from 'https://cdn.jsdelivr.net/npm/c2pa@${version}/+esm';
1516

1617
(async () => {
18+
// Initialize the c2pa-js SDK
19+
const c2pa = await createC2pa({
20+
wasmSrc:
21+
'https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/assets/wasm/toolkit_bg.wasm',
22+
workerSrc:
23+
'https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/c2pa.worker.min.js',
24+
});
25+
26+
1727
let output: string[] = [];
1828

1929
const c2pa = await createC2pa({
@@ -54,6 +64,7 @@ const sampleImage =
5464
</tr>
5565
`;
5666
});
67+
5768
} else {
5869
output.push(`
5970
<tr>
@@ -63,5 +74,33 @@ const sampleImage =
6374
}
6475

6576
document.querySelector('#results tbody')!.innerHTML = output.join('');
77+
6678
})();
79+
```
80+
81+
With an HTML page like this:
82+
83+
```html
84+
<!DOCTYPE html>
85+
<html lang="en">
86+
<head>
87+
<meta charset="UTF-8" />
88+
<link rel="icon" type="image/svg+xml" href="../../favicon.svg" />
89+
<link rel="stylesheet" href="../../styles.css" />
90+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
91+
<title>active-manifest</title>
92+
</head>
93+
<body>
94+
<table id="results">
95+
<thead>
96+
<th>Property</th>
97+
<th>Value</th>
98+
</thead>
99+
<tbody>
100+
<td colspan="3">Loading&hellip;</td>
101+
</tbody>
102+
</table>
103+
<script type="module" src="./main.ts"></script>
104+
</body>
105+
</html>
67106
```

docs/tasks/includes/_js-read.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@ Use [`c2pa.read`](../../docs/js-sdk/api/c2pa.c2pa#methods) to read manifest data
99
- **validationStatus**: A list of any validation errors encountered. See [Validation](../../docs/js-sdk/guides/validation) for more information.
1010

1111
```js
12+
const version = '0.30.14';
13+
const sampleImage = '<IMAGE_URL>';
14+
15+
import { createC2pa } from 'https://cdn.jsdelivr.net/npm/c2pa@${version}/+esm';
16+
17+
(async () => {
18+
// Initialize the c2pa-js SDK
19+
const c2pa = await createC2pa({
20+
wasmSrc:
21+
'https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/assets/wasm/toolkit_bg.wasm',
22+
workerSrc:
23+
'https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/c2pa.worker.min.js',
24+
});
25+
1226
try {
1327
// Read in image and get a manifest store
1428
const { manifestStore } = await c2pa.read(sampleImage);
@@ -21,4 +35,4 @@ Use [`c2pa.read`](../../docs/js-sdk/api/c2pa.c2pa#methods) to read manifest data
2135
console.error('Error reading image:', err);
2236
}
2337
})();
24-
```
38+
```

docs/tasks/includes/_python-build.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ This is an example of how to assign a manifest to an asset and sign the claim us
44
Use a `Builder` object to add a manifest to an asset.
55

66
```python
7+
# Import the C2PA Python package.
8+
from c2pa import *
9+
10+
# Import standard general-purpose packages.
11+
import os
12+
import io
13+
import logging
14+
import json
15+
import base64
16+
717
try:
818
# Define a function to sign the claim bytes.
919
# In this case we are using a pre-defined sign_ps256 method, passing in our private cert.

docs/tasks/includes/_python-get-resources.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ Retrieve binary resources such as thumbnails from the manifest data, use the `re
66
_NOTE: Need to add example of using `reader.resource_to_stream()`._
77

88
```py
9+
# Import the C2PA Python package.
10+
from c2pa import *
11+
12+
# Import standard general-purpose packages.
13+
import os
14+
import io
15+
import logging
16+
import json
17+
918
try:
1019
# Create a reader from a file path.
1120
reader = c2pa.Reader.from_file("path/to/media_file.jpg")

docs/tasks/includes/_python-read.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ Use the `json()` method to return a JSON manifest report; If there are validatio
66
An asset file may contain many manifests in a manifest store. The most recent manifest is identified by the value of the `active_manifest` field in the manifests map.
77

88
```py
9+
# Import the C2PA Python package.
10+
from c2pa import *
11+
12+
# Import standard general-purpose packages.
13+
import os
14+
import io
15+
import logging
16+
import json
17+
918
try:
1019
# Create a reader from a file path.
1120
reader = c2pa.Reader.from_file("path/to/media_file.jpg")

docs/tasks/includes/_rust-build.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ This is an example of how to assign a manifest to an asset and sign the claim us
33
This example is from [`c2pa-rs/sdk/examples/v2api.rs`](https://github.com/contentauth/c2pa-rs/blob/main/sdk/examples/v2api.rs#L88C5-L134C1):
44

55
```rust
6-
let json = manifest_def(title, format);
6+
use std::io::{Cursor, Seek};
7+
8+
use anyhow::Result;
9+
use c2pa::{
10+
crypto::raw_signature::SigningAlg, settings::Settings, validation_results::ValidationState,
11+
Builder, CallbackSigner, Reader,
12+
};
13+
use serde_json::json;
714

15+
let json = manifest_def(title, format);
816
let mut builder = Builder::from_json(&json)?;
17+
918
builder.add_ingredient_from_stream(
1019
json!({
1120
"title": parent_name,

docs/tasks/includes/_rust-get-resources.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ This is from [`resource_to_stream`](https://docs.rs/c2pa/latest/c2pa/struct.Read
66

77
```rust
88
use c2pa::Reader;
9-
let stream = std::io::Cursor::new(Vec::new());
10-
let reader = Reader::from_file("path/to/file.jpg").unwrap();
11-
let manifest = reader.active_manifest().unwrap();
12-
let uri = &manifest.thumbnail_ref().unwrap().identifier;
13-
let bytes_written = reader.resource_to_stream(uri, stream).unwrap();
9+
#[cfg(feature = "file_io")]
10+
{
11+
let stream = std::io::Cursor::new(Vec::new());
12+
let reader = Reader::from_file("path/to/file.jpg").unwrap();
13+
let manifest = reader.active_manifest().unwrap();
14+
let uri = &manifest.thumbnail_ref().unwrap().identifier;
15+
let bytes_written = reader.resource_to_stream(uri, stream).unwrap();
16+
}
1417
```
1518

1619
This is from [`c2pa-rs/examples/v2api.rs`](https://github.com/contentauth/c2pa-rs/blob/main/sdk/examples/v2api.rs#L138):
1720

1821
```rust
22+
use std::io::{Cursor, Seek};
23+
24+
use anyhow::Result;
25+
use c2pa::{
26+
crypto::raw_signature::SigningAlg, settings::Settings, validation_results::ValidationState,
27+
Builder, CallbackSigner, Reader,
28+
};
29+
use serde_json::json;
30+
1931
let reader = Reader::from_stream(format, &mut dest)?;
2032

2133
// extract a thumbnail image from the ManifestStore

0 commit comments

Comments
 (0)