Skip to content

Commit a0d7c02

Browse files
committed
fix: refactor & docs
1 parent 006d2ab commit a0d7c02

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

docs/usage.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ For complete working examples, see the [examples folder](https://github.com/cont
99
Import the objects needed from the API:
1010

1111
```py
12-
from c2pa import Builder, Reader, Signer, C2paSignerInfo, C2paSigningAlg
12+
from c2pa import Builder, Reader, Signer, C2paSigningAlg, C2paSignerInfo
1313
```
1414

1515
If you want to use per-instance configuration with `Context` and `Settings`:
@@ -46,11 +46,13 @@ manifest_json = json.dumps({
4646
})
4747
```
4848

49-
## File-based operations
49+
## File-based operation
5050

5151
### Read and validate C2PA data
5252

53-
Use the `Reader` to read C2PA data from a file. The Reader examines the file for C2PA data and generates a report of any data it finds. If there are validation errors, the report includes a `validation_status` field.
53+
Use the `Reader` to read C2PA data from the specified asset file.
54+
55+
This examines the specified media file for C2PA data and generates a report of any data it finds. If there are validation errors, the report includes a `validation_status` field.
5456

5557
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. The manifests may contain binary resources such as thumbnails which can be retrieved with `resource_to_stream` using the associated `identifier` field values and a `uri`.
5658

@@ -60,16 +62,16 @@ NOTE: For a comprehensive reference to the JSON manifest structure, see the [Man
6062

6163
```py
6264
try:
63-
# Create a reader from a file path
65+
# Create a Reader from a file path.
6466
with Reader("path/to/media_file.jpg") as reader:
65-
# Print manifest store as JSON
67+
# Print manifest store as JSON.
6668
print("Manifest store:", reader.json())
6769

68-
# Get the active manifest
70+
# Get the active manifest.
6971
manifest = json.loads(reader.json())
7072
active_manifest = manifest["manifests"][manifest["active_manifest"]]
7173
if active_manifest:
72-
# Get the uri to the manifest's thumbnail and write it to a file
74+
# Get the uri to the manifest's thumbnail and write it to a file.
7375
uri = active_manifest["thumbnail"]["identifier"]
7476
with open("thumbnail.jpg", "wb") as f:
7577
reader.resource_to_stream(uri, f)
@@ -99,7 +101,7 @@ except Exception as err:
99101

100102
### Add a signed manifest
101103

102-
**WARNING**: These examples access the private key and security certificate directly from the local file system. This is fine during development, but doing so in production may be insecure. Instead use a Key Management Service (KMS) or a hardware security module (HSM) to access the certificate and key; for example as shown in the [C2PA Python Example](https://github.com/contentauth/c2pa-python-example).
104+
**WARNING**: This example accesses the private key and security certificate directly from the local file system. This is fine during development, but doing so in production may be insecure. Instead use a Key Management Service (KMS) or a hardware security module (HSM) to access the certificate and key; for example as show in the [C2PA Python Example](https://github.com/contentauth/c2pa-python-example).
103105

104106
#### Signing without Context
105107

@@ -120,7 +122,7 @@ try:
120122
ta_url=b"http://timestamp.digicert.com"
121123
)
122124

123-
# Create signer from the signer info
125+
# Create signer using the defined SignerInfo
124126
signer = Signer.from_info(signer_info)
125127

126128
# Create builder with manifest and add ingredients
@@ -133,7 +135,7 @@ try:
133135
with open("path/to/source.jpg", "rb") as source, open("path/to/output.jpg", "w+b") as dest:
134136
builder.sign(signer, "image/jpeg", source, dest)
135137

136-
# Verify the signed file
138+
# Verify the signed file by reading data from the signed output file
137139
with Reader("path/to/output.jpg") as reader:
138140
manifest_store = json.loads(reader.json())
139141
active_manifest = manifest_store["manifests"][manifest_store["active_manifest"]]
@@ -167,7 +169,7 @@ try:
167169
ingredient_json = json.dumps({"title": "Ingredient Image"})
168170
builder.add_ingredient(ingredient_json, "image/jpeg", ingredient_file)
169171

170-
# Sign using file paths (convenience method)
172+
# Sign using file paths
171173
builder.sign_file("path/to/source.jpg", "path/to/output.jpg", signer)
172174

173175
# Verify the signed file with the same context
@@ -364,7 +366,7 @@ assert isinstance(ctx, ContextProvider)
364366
### Migrating from load_settings
365367

366368
The `load_settings()` function that set settings in a thread-local fashion is deprecated.
367-
Replace it with `Settings` and `Context` usage to propagate configurations:
369+
Replace it with `Settings` and `Context` usage to propagate configurations (do not mix legacy and new APIs):
368370

369371
```py
370372
# Before:
@@ -383,7 +385,7 @@ reader = Reader("file.jpg", context=ctx)
383385

384386
## Stream-based operations
385387

386-
Instead of working with files, you can read, validate, and add a signed manifest to streamed data.
388+
Instead of working with files, you can read, validate, and add a signed manifest to streamed data. This example is similar to what the file-based example does.
387389

388390
### Read and validate C2PA data using streams
389391

0 commit comments

Comments
 (0)