You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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).
91
93
92
-
### ContextBuilder (fluent API)
94
+
### Using ContextBuilder
93
95
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:
95
97
96
98
```py
97
99
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:
131
133
132
134
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).
133
135
134
-
### ContextProvider (abstract base class)
136
+
### Using ContextProvider
135
137
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:
137
139
138
140
-`is_valid` (bool): Whether the provider is in a usable state.
139
141
-`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
154
156
155
157
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`.
156
158
157
-
NOTE: For a comprehensive reference to the JSON manifest structure, see the [Manifest store reference](https://opensource.contentauthenticity.org/docs/manifest/manifest-ref).
# Get the uri to the manifest's thumbnail and write it to a file.
173
-
uri = active_manifest["thumbnail"]["identifier"]
174
-
withopen("thumbnail.jpg", "wb") as f:
175
-
reader.resource_to_stream(uri, f)
176
-
177
-
exceptExceptionas 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).
182
161
183
162
Pass a `Context` to apply custom settings to the Reader, such as trust anchors or verification flags.
184
163
@@ -199,51 +178,8 @@ except Exception as err:
199
178
200
179
### Add a signed manifest
201
180
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
-
withopen("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
-
withopen("path/to/ingredient.jpg", "rb") as ingredient_file:
> 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).
247
183
248
184
Pass a `Context` to the Builder to apply custom settings during signing. The signer is still passed explicitly to `builder.sign()`.
249
185
@@ -284,28 +220,7 @@ except Exception as e:
284
220
285
221
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.
286
222
287
-
### Read and validate C2PA data using streams
288
-
289
-
#### Stream reading without Context
290
-
291
-
```py
292
-
try:
293
-
withopen("path/to/media_file.jpg", "rb") as stream:
**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
-
withopen("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
-
withopen("path/to/ingredient.jpg", "rb") as ingredient_file:
> 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).
0 commit comments