Skip to content

Commit 3172d41

Browse files
author
Rand McKinney
committed
Edits to README
1 parent d877ed3 commit 3172d41

File tree

1 file changed

+70
-43
lines changed

1 file changed

+70
-43
lines changed

README.md

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,84 @@
11
# C2PA Python
22

3-
Python bindings for the C2PA Content Authenticity Initiative (CAI) library
3+
Python bindings for the C2PA Content Authenticity Initiative (CAI) library.
44

5-
This library allows you to read and validate c2pa data in supported media files
6-
And to add signed manifests to supported media files.
5+
This library enables you to read and validate C2PA data in supported media files and add signed manifests to supported media files.
76

87
## Installation
98

10-
```pip install c2pa-python```
9+
Install from PyPI by entering this command:
10+
11+
```
12+
pip install c2pa-python
13+
```
1114

1215
## Usage
1316

1417
### Import
1518

16-
```import c2pa-python as c2pa```
19+
Import the C2PA module as follows:
20+
21+
```py
22+
import c2pa-python as c2pa
23+
```
24+
25+
### Reading and validating C2PA data in a file
1726

18-
### Reading and Validating C2PA data in a file
27+
Use the `verify_from_file_json` function to read C2PA data from the specified file:
1928

20-
Read any C2PA data from a given file
29+
```py
30+
json_store = c2pa.verify_from_file_json("path/to/media_file.jpg", data_dir)
31+
```
32+
33+
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).
2134

22-
```json_store = c2pa.verify_from_file_json("path/to/media_file.jpg", data_dir)```
35+
A media 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.
2336

24-
This will examine any supported media file for c2pa data and generate
25-
a JSON report of any data it finds. The report will include a validation_status field if any validation errors were found.
37+
If the optional `data_dir` is 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.
2638

27-
A media file may contain many manifests in a manifest store. The most recent manifest can be accessed by looking up the active_manifest field value in the manifests map.
39+
NOTE: For a comprehensive reference to the JSON manifest structure, see the [CAI manifest store reference](https://contentauth.github.io/json-manifest-reference/manifest-reference).
2840

29-
If the optional data_dir is provided, any binary resources, such as thumbnails, icons and c2pa_data will be extracted into that directory.
30-
These files will be referenced by the identifier fields in the manifest store report.
41+
### Adding a signed manifest to a media file
3142

43+
The `add_manifest_to_file_json` function adds a signed manifest to a media file.
3244

33-
### Adding a Signed Manifest to a media file
34-
The source is the media file which should receive new c2pa data.
35-
The destination will have a copy of the source with the data added.
36-
The manifest Json is a a JSON formatted string containing the data you want to add.
37-
(see: [Generating SignerInfo](#generating-signerinfo) for how to construct SignerInfo)
38-
The optional data_dir allows you to load resource files referenced from manifest_json identifiers.
39-
When building your manifest, any files referenced by identifier fields will be loaded relative to this path.
40-
This allows you to load thumbnails, icons and manifest data for ingredients
45+
```py
46+
result = c2pa.add_manifest_to_file_json("path/to/source.jpg",
47+
"path/to/dest.jpg",
48+
manifest_json,
49+
sign_info,
50+
data_dir)
51+
```
4152

42-
```result = c2pa.add_manifest_to_file_json("path/to/source.jpg", "path/to/dest.jpg", manifest_json, sign_info, data_dir)```
53+
The parameters (in order) are:
54+
- The source media file that will receive new C2PA data.
55+
- The destination file that will contain a copy of the source file with the manifest data added.
56+
- `manifest_json`, a JSON-formatted string containing the manifest data you want to add; see [Creating a manifest JSON definition file](#creating-a-manifest-json-definition-file) below.
57+
- `sign_info`, a `SignerInfo` object instance; see [Generating SignerInfo](#generating-signerinfo) below.
58+
- The optional `data_dir` enables you to load resource files referenced from `manifest_json` identifiers. When building your manifest, any files referenced by identifier fields are loaded relative to this path. This enables you to load thumbnails, icons, and manifest data for ingredients.
4359

4460
### Generating SignerInfo
4561

46-
Set up the signer info from pem and key files.
62+
A `SignerInfo` object contains information about a signature. To create an instance of `SignerInfo`, first set up the signer information from the public and private key `.pem` files as follows:
4763

48-
```certs = open("path/to/public_certs.pem","rb").read()```
49-
```prv_key = open("path/to/private_key.pem","rb").read()```
64+
```py
65+
certs = open("path/to/public_certs.pem","rb").read()
66+
prv_key = open("path/to/private_key.pem","rb").read()
67+
```
5068

51-
Then create a new SignerInfo instance using those keys.
52-
You must specify the signing algorithm used and may optionally add a time stamp authority URL.
69+
Then create a new `SignerInfo` instance using those keys as follows, specifying the signing algorithm used and optionally a time stamp authority URL:
5370

54-
```sign_info = c2pa.SignerInfo(certs, priv_key, "es256", "http://timestamp.digicert.com") ```
71+
```py
72+
sign_info = c2pa.SignerInfo(certs, priv_key, "es256", "http://timestamp.digicert.com")
73+
```
5574

75+
For the list of supported signing algorithms, see [Creating and using an X.509 certificate](https://opensource.contentauthenticity.org/docs/c2patool/x_509).
5676

57-
### Creating a Manifest Json Definition File
77+
### Creating a manifest JSON definition file
5878

59-
The manifest json string defines the c2pa to add to the file.
79+
The manifest JSON string defines the C2PA manifest to add to the file.
6080

61-
```
81+
```py
6282
manifest_json = json.dumps({
6383
"claim_generator": "python_test/0.1",
6484
"assertions": [
@@ -75,28 +95,35 @@ manifest_json = json.dumps({
7595
}
7696
]
7797
})
78-
```
79-
## Development
80-
81-
It is best to set up a virtual environment for development and testing
82-
https://virtualenv.pypa.io/en/latest/installation.html
98+
```
8399

84-
We use maturin for packaging Rust in Python. It can can be installed with pip
100+
## Development
85101

86-
```pip install maturin```
102+
It is best to [set up a virtual environment](https://virtualenv.pypa.io/en/latest/installation.html) for development and testing.
87103

88-
You will also need to install uniffi bindgen and pytest for testing
104+
We use `maturin` for packaging Rust in Python. Install it as follows:
89105

90-
``pip install uniffi_bindgen``
106+
```
107+
pip install maturin
108+
```
91109

92-
``pip install -U pytest``
110+
You also must install `uniffi`, `bindgen`, and `pytest` for testing
93111

94-
``pip install <path to.whl> --force-reinstall``
112+
```
113+
pip install uniffi_bindgen
114+
pip install -U pytest
115+
pip install <path-to-whl> --force-reinstall
116+
```
95117

96118
### Testing
97119

98-
```pytest```
120+
We use [PyTest](https://docs.pytest.org/) for testing.
121+
122+
Run tests by entering this command:
99123

124+
```
125+
pytest
126+
```
100127

101128
## Supported file formats
102129

0 commit comments

Comments
 (0)