Skip to content

Commit a59e748

Browse files
authored
Merge pull request #3 from contentauth/api_alignment
Use the c2pa_c rust library and align function names.
2 parents b59a2f0 + 103cc28 commit a59e748

File tree

9 files changed

+81
-253
lines changed

9 files changed

+81
-253
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "c2pa-python"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["Gavin Peacock <[email protected]"]
66

@@ -10,7 +10,8 @@ name = "c2pa_python"
1010
crate-type = ["cdylib"]
1111

1212
[dependencies]
13-
c2pa = {version="0.26.0", features = ["file_io", "add_thumbnails", "fetch_remote_manifests"]}
13+
c2pa-c = { git = "https://github.com/contentauth/c2pa-c.git", branch = "gpeacock/rlib"}
14+
#c2pa = {version="0.26.0", features = ["file_io", "add_thumbnails", "fetch_remote_manifests"]}
1415
serde = { version = "1.0", features = ["derive"] }
1516
serde_derive = "1.0"
1617
serde_json = "1.0"

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ import c2pa_python as c2pa
2626

2727
### Read and validate C2PA data in a file
2828

29-
Use the `verify_from_file_json` function to read C2PA data from the specified file:
29+
Use the `read_file` function to read C2PA data from the specified file:
3030

3131
```py
32-
json_store = c2pa.verify_from_file_json("path/to/media_file.jpg", "path/to/data_dir")
32+
json_store = c2pa.read_file("path/to/media_file.jpg", "path/to/data_dir")
3333
```
3434

3535
This function examines the specified media file for C2PA data and generates a JSON report of any data it finds. If there are validation errors, the report includes a `validation_status` field. For a summary of supported media types, see [Supported file formats](#supported-file-formats).
@@ -42,10 +42,10 @@ NOTE: For a comprehensive reference to the JSON manifest structure, see the [CAI
4242

4343
### Add a signed manifest to a media file
4444

45-
Use the `add_manifest_to_file_json` function to add a signed manifest to a media file.
45+
Use the `sign_file` function to add a signed manifest to a media file.
4646

4747
```py
48-
result = c2pa.add_manifest_to_file_json("path/to/source.jpg",
48+
result = c2pa.sign_file("path/to/source.jpg",
4949
"path/to/dest.jpg",
5050
manifest_json,
5151
sign_info,
@@ -71,7 +71,7 @@ prv_key = open("path/to/private_key.pem","rb").read()
7171
Then create a new `SignerInfo` instance using the keys as follows, specifying the signing algorithm used and optionally a time stamp authority URL:
7272

7373
```py
74-
sign_info = c2pa.SignerInfo(certs, priv_key, "es256", "http://timestamp.digicert.com")
74+
sign_info = c2pa.SignerInfo("es256", certs, priv_key, "http://timestamp.digicert.com")
7575
```
7676

7777
For the list of supported signing algorithms, see [Creating and using an X.509 certificate](https://opensource.contentauthenticity.org/docs/c2patool/x_509).
@@ -124,7 +124,21 @@ We use [PyTest](https://docs.pytest.org/) for testing.
124124
Run tests by entering this command:
125125

126126
```
127+
source .venv/bin/activate
128+
maturin develop
127129
pytest
130+
deactivate
131+
```
132+
133+
### Example
134+
135+
Run the example code like this:
136+
137+
```
138+
source .venv/bin/activate
139+
maturin develop
140+
python3 tests/training.py
141+
deactivate
128142
```
129143

130144
## Supported file formats
@@ -147,6 +161,19 @@ pytest
147161
| `wav` | `audio/x-wav` |
148162
| `webp` | `image/webp` |
149163

164+
165+
## Change Notes:
166+
167+
Version 0.3.0 changes:
168+
There are some breaking changes to align with future APIs:
169+
- `C2paSignerInfo` moves the `alg` to the first parameter from the 3rd.
170+
- `c2pa.verify_from_file_json` is now `c2pa.read_file`.
171+
- `c2pa.ingredient_from_file_json` is now `c2pa.read_ingredient_file`.
172+
- `c2pa.add_manifest_to_file_json` is now `c2pa.sign_file`.
173+
- There are many more specific errors types now, and Error messages always start with the name of the error i.e (str(err.value).startswith("ManifestNotFound")).
174+
- The ingredient thumbnail identifier may be jumbf uri reference if a valid thumb already exists in the active manifest.
175+
- Extracted file paths for read_file now use a folder structure and different naming conventions.
176+
150177
## License
151178

152179
This package is distributed under the terms of both the [MIT license](https://github.com/contentauth/c2pa-rs/blob/main/LICENSE-MIT) and the [Apache License (Version 2.0)](https://github.com/contentauth/c2pa-rs/blob/main/LICENSE-APACHE).

src/c2pa.udl

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,37 @@ namespace c2pa {
33
string version();
44
string sdk_version();
55
[Throws=Error]
6-
string verify_from_file_json([ByRef] string path, string? data_dir);
6+
string read_file([ByRef] string path, string? data_dir);
77
[Throws=Error]
8-
string ingredient_from_file_json([ByRef] string path, [ByRef] string data_dir);
8+
string read_ingredient_file([ByRef] string path, [ByRef] string data_dir);
99
[Throws=Error]
10-
sequence<u8> add_manifest_to_file_json([ByRef] string source, [ByRef] string dest, [ByRef] string manifest, SignerInfo signer_info, string? data_dir);
10+
sequence<u8> sign_file([ByRef] string source, [ByRef] string dest, [ByRef] string manifest, [ByRef] SignerInfo signer_info, string? data_dir);
1111
};
1212

1313
[Error]
1414
enum Error {
15+
"Assertion",
16+
"AssertionNotFound",
17+
"Decoding",
18+
"Encoding",
19+
"FileNotFound",
20+
"Io",
1521
"Json",
16-
"Sdk"
22+
"Manifest",
23+
"ManifestNotFound",
24+
"NotSupported",
25+
"Other",
26+
"NullParameter",
27+
"RemoteManifest",
28+
"ResourceNotFound",
29+
"Signature",
30+
"Verify"
1731
};
1832

1933
dictionary SignerInfo {
20-
sequence<u8> signcert;
21-
sequence<u8> pkey;
2234
string alg;
23-
string? tsa_url;
35+
sequence<u8> sign_cert;
36+
sequence<u8> private_key;
37+
string? ta_url;
2438
};
2539

src/error.rs

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/json_api.rs

Lines changed: 0 additions & 107 deletions
This file was deleted.

src/lib.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,13 @@
1313
/// This module exports a C2PA library
1414
use std::env;
1515

16-
mod error;
17-
mod json_api;
18-
mod signer_info;
19-
20-
pub use error::{Error, Result};
21-
pub use json_api::*;
22-
pub use signer_info::SignerInfo;
16+
pub(crate) use c2pa_c::{
17+
read_file, read_ingredient_file, sdk_version, sign_file, Error, SignerInfo,
18+
};
2319

2420
/// Returns the version of this library
2521
fn version() -> String {
2622
String::from(env!("CARGO_PKG_VERSION"))
2723
}
2824

29-
/// Returns the version of the c2pa SDK used in this library
30-
fn sdk_version() -> String {
31-
String::from(c2pa::VERSION)
32-
}
33-
3425
uniffi::include_scaffolding!("c2pa");

src/signer_info.rs

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)