Skip to content

Commit 70ffa3c

Browse files
committed
Remove sections about not using Context, other clean up
1 parent 3697026 commit 70ffa3c

3 files changed

Lines changed: 51 additions & 174 deletions

File tree

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ Features:
1212
- Add assertions and ingredients to assets.
1313
- Examples and unit tests to demonstrate usage.
1414

15+
<div style={{display: 'none'}}>
16+
17+
For the best experience, read the docs on the [CAI Open Source SDK documentation website](https://opensource.contentauthenticity.org/docs/c2pa-c).
18+
19+
If you want to view the documentation in GitHub, see:
20+
- [Using the Python library](docs/usage.md)
21+
- [Supported formats](https://github.com/contentauth/c2pa-rs/blob/main/docs/supported-formats.md)
22+
- [Configuring the SDK using `Context` and `Settings`](docs/context-settings.md)
23+
- [Using Builder intents](docs/intents.md) to ensure spec-compliant manifests
24+
- Using [working stores and archvies](docs/working-stores.md)
25+
- Selectively constructing manifests by [filtering actions and ingredients](docs/selective-manifests.md)
26+
- [Diagram of public classes in the Python library and their relationships](docs/class-diagram.md)
27+
- [Release notes](docs/release-notes.md)
28+
29+
</div>
30+
1531
## Prerequisites
1632

1733
This library requires Python version 3.10+.

docs/usage.md

Lines changed: 14 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ manifest_json = json.dumps({
5252

5353
## Settings, Context, and ContextProvider
5454

55-
The `Settings` and `Context` classes provide per-instance configuration for `Reader` and `Builder` operations, replacing the global `load_settings()` function, which is now deprecated. See [Context and settings](context-settings.md) for details.
55+
The `Settings` and `Context` classes provide per-instance configuration for `Reader` and `Builder` operations, replacing the global `load_settings()` function, which is now deprecated.
56+
57+
See [Context and settings](context-settings.md) for details.
5658

5759
### Settings
5860

@@ -89,9 +91,9 @@ builder = Builder(manifest_json, ctx)
8991

9092
For full details on configuring `Context` and using it with `Reader` and `Builder`, see [Using Context](context-settings.md#using-context) and the [Settings reference](context-settings.md#settings-reference).
9193

92-
### ContextBuilder (fluent API)
94+
### Using ContextBuilder
9395

94-
`ContextBuilder` provides a fluent interface for constructing a `Context`. Use `Context.builder()` to get started.
96+
`ContextBuilder` provides a fluent interface for constructing a `Context`. Use `Context.builder()` to get started; for example:
9597

9698
```py
9799
from c2pa import Context, ContextBuilder, Settings, Signer
@@ -131,9 +133,9 @@ with open("source.jpg", "rb") as src, open("output.jpg", "w+b") as dst:
131133

132134
If both an explicit signer and a context signer are available, the explicit signer takes precedence. For more details, including remote signers, see [Configuring signers](context-settings.md#configuring-signers).
133135

134-
### ContextProvider (abstract base class)
136+
### Using ContextProvider
135137

136-
`ContextProvider` is an abstract base class (ABC) that defines the interface `Reader` and `Builder` use to access a context. It requires two properties:
138+
`ContextProvider` is an abstract base class that defines the interface `Reader` and `Builder` use to access a context. It requires two properties:
137139

138140
- `is_valid` (bool): Whether the provider is in a usable state.
139141
- `execution_context`: The raw native context pointer (`C2paContext` handle).
@@ -154,31 +156,8 @@ This examines the specified media file for C2PA data and generates a report of a
154156

155157
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`.
156158

157-
NOTE: For a comprehensive reference to the JSON manifest structure, see the [Manifest store reference](https://opensource.contentauthenticity.org/docs/manifest/manifest-ref).
158-
159-
#### Reading without Context
160-
161-
```py
162-
try:
163-
# Create a Reader from a file path.
164-
with Reader("path/to/media_file.jpg") as reader:
165-
# Print manifest store as JSON.
166-
print("Manifest store:", reader.json())
167-
168-
# Get the active manifest.
169-
manifest = json.loads(reader.json())
170-
active_manifest = manifest["manifests"][manifest["active_manifest"]]
171-
if active_manifest:
172-
# Get the uri to the manifest's thumbnail and write it to a file.
173-
uri = active_manifest["thumbnail"]["identifier"]
174-
with open("thumbnail.jpg", "wb") as f:
175-
reader.resource_to_stream(uri, f)
176-
177-
except Exception as err:
178-
print(err)
179-
```
180-
181-
#### Reading with Context
159+
> [!NOTE]
160+
> For a comprehensive reference to the JSON manifest structure, see the [Manifest store reference](https://opensource.contentauthenticity.org/docs/manifest/manifest-ref).
182161
183162
Pass a `Context` to apply custom settings to the Reader, such as trust anchors or verification flags.
184163

@@ -199,51 +178,8 @@ except Exception as err:
199178

200179
### Add a signed manifest
201180

202-
**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).
203-
204-
#### Signing without Context
205-
206-
Use a `Builder` and `Signer` to add a manifest to an asset:
207-
208-
```py
209-
try:
210-
# Load certificate and key files
211-
with open("path/to/cert.pem", "rb") as cert_file, open("path/to/key.pem", "rb") as key_file:
212-
cert_data = cert_file.read()
213-
key_data = key_file.read()
214-
215-
# Create signer info with the correct field names
216-
signer_info = C2paSignerInfo(
217-
alg=C2paSigningAlg.PS256,
218-
sign_cert=cert_data,
219-
private_key=key_data,
220-
ta_url=b"http://timestamp.digicert.com"
221-
)
222-
223-
# Create signer using the defined SignerInfo
224-
signer = Signer.from_info(signer_info)
225-
226-
# Create builder with manifest and add ingredients
227-
with Builder(manifest_json) as builder:
228-
with open("path/to/ingredient.jpg", "rb") as ingredient_file:
229-
ingredient_json = json.dumps({"title": "Ingredient Image"})
230-
builder.add_ingredient(ingredient_json, "image/jpeg", ingredient_file)
231-
232-
# Sign the file (dest must be opened in w+b mode)
233-
with open("path/to/source.jpg", "rb") as source, open("path/to/output.jpg", "w+b") as dest:
234-
builder.sign(signer, "image/jpeg", source, dest)
235-
236-
# Verify the signed file by reading data from the signed output file
237-
with Reader("path/to/output.jpg") as reader:
238-
manifest_store = json.loads(reader.json())
239-
active_manifest = manifest_store["manifests"][manifest_store["active_manifest"]]
240-
print("Signed manifest:", active_manifest)
241-
242-
except Exception as e:
243-
print("Failed to sign manifest store: " + str(e))
244-
```
245-
246-
#### Signing with Context
181+
> [!WARNING]
182+
> 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 is 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).
247183
248184
Pass a `Context` to the Builder to apply custom settings during signing. The signer is still passed explicitly to `builder.sign()`.
249185

@@ -284,28 +220,7 @@ except Exception as e:
284220

285221
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.
286222

287-
### Read and validate C2PA data using streams
288-
289-
#### Stream reading without Context
290-
291-
```py
292-
try:
293-
with open("path/to/media_file.jpg", "rb") as stream:
294-
with Reader("image/jpeg", stream) as reader:
295-
print("Manifest store:", reader.json())
296-
297-
manifest = json.loads(reader.json())
298-
active_manifest = manifest["manifests"][manifest["active_manifest"]]
299-
if active_manifest:
300-
uri = active_manifest["thumbnail"]["identifier"]
301-
with open("thumbnail.jpg", "wb") as f:
302-
reader.resource_to_stream(uri, f)
303-
304-
except Exception as err:
305-
print(err)
306-
```
307-
308-
#### Stream reading with Context
223+
### Read and validate manifest data
309224

310225
```py
311226
try:
@@ -322,46 +237,8 @@ except Exception as err:
322237

323238
### Add a signed manifest to a stream
324239

325-
**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).
326-
327-
#### Stream signing without Context
328-
329-
```py
330-
try:
331-
with open("path/to/cert.pem", "rb") as cert_file, open("path/to/key.pem", "rb") as key_file:
332-
cert_data = cert_file.read()
333-
key_data = key_file.read()
334-
335-
signer_info = C2paSignerInfo(
336-
alg=C2paSigningAlg.PS256,
337-
sign_cert=cert_data,
338-
private_key=key_data,
339-
ta_url=b"http://timestamp.digicert.com"
340-
)
341-
342-
signer = Signer.from_info(signer_info)
343-
344-
with Builder(manifest_json) as builder:
345-
with open("path/to/ingredient.jpg", "rb") as ingredient_file:
346-
ingredient_json = json.dumps({"title": "Ingredient Image"})
347-
builder.add_ingredient(ingredient_json, "image/jpeg", ingredient_file)
348-
349-
# Sign using streams (dest must be opened in w+b mode)
350-
with open("path/to/source.jpg", "rb") as source, open("path/to/output.jpg", "w+b") as dest:
351-
builder.sign(signer, "image/jpeg", source, dest)
352-
353-
# Verify the signed file
354-
with open("path/to/output.jpg", "rb") as stream:
355-
with Reader("image/jpeg", stream) as reader:
356-
manifest_store = json.loads(reader.json())
357-
active_manifest = manifest_store["manifests"][manifest_store["active_manifest"]]
358-
print("Signed manifest:", active_manifest)
359-
360-
except Exception as e:
361-
print("Failed to sign manifest store: " + str(e))
362-
```
363-
364-
#### Stream signing with Context
240+
> [!WARNING]
241+
> 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 IS 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).
365242
366243
```py
367244
try:

0 commit comments

Comments
 (0)