30
30
31
31
Example of loading root, timestamp and snapshot:
32
32
33
- >>> # Load local root (RepositoryErrors here stop the update)
33
+ >>> # Load local root (MetadataError here stop the update)
34
34
>>> with open(root_path, "rb") as f:
35
35
>>> trusted_set = TrustedMetadataSet(f.read())
36
36
>>>
42
42
>>> try:
43
43
>>> with open(timestamp_path, "rb") as f:
44
44
>>> trusted_set.update_timestamp(f.read())
45
- >>> except (RepositoryError , OSError):
45
+ >>> except (MetadataError , OSError):
46
46
>>> pass # failure to load a local file is ok
47
47
>>>
48
48
>>> with download(Timestamp.type) as f:
52
52
>>> try:
53
53
>>> with open(snapshot_path, "rb") as f:
54
54
>>> trusted_set.update_snapshot(f.read())
55
- >>> except (RepositoryError , OSError):
55
+ >>> except (MetadataError , OSError):
56
56
>>> # local snapshot is not valid, load from remote
57
- >>> # (RepositoryErrors here stop the update)
57
+ >>> # (MetadataError here stop the update)
58
58
>>> with download(Snapshot.type, version) as f:
59
59
>>> trusted_set.update_snapshot(f.read())
60
60
61
61
TODO:
62
62
* exceptions are not final: the idea is that client could just handle
63
- a generic RepositoryError that covers every issue that server provided
63
+ a generic MetadataError that covers every issue that server provided
64
64
metadata could inflict (other errors would be user errors), but this is not
65
65
yet the case
66
66
* Progress through Specification update process should be documented
@@ -96,7 +96,7 @@ def __init__(self, root_data: bytes):
96
96
all metadata in the TrustedMetadataSet
97
97
98
98
Raises:
99
- RepositoryError : Metadata failed to load or verify. The actual
99
+ MetadataVerificationError : Metadata failed to load or verify. The actual
100
100
error type and content will contain more details.
101
101
"""
102
102
self ._trusted_set : Dict [str , Metadata ] = {}
@@ -151,7 +151,7 @@ def update_root(self, data: bytes) -> Metadata[Root]:
151
151
data: unverified new root metadata as bytes
152
152
153
153
Raises:
154
- RepositoryError : Metadata failed to load or verify. The actual
154
+ MetadataError : Metadata failed to load or verify. The actual
155
155
error type and content will contain more details.
156
156
157
157
Returns:
@@ -164,10 +164,10 @@ def update_root(self, data: bytes) -> Metadata[Root]:
164
164
try :
165
165
new_root = Metadata [Root ].from_bytes (data )
166
166
except DeserializationError as e :
167
- raise exceptions .RepositoryError ("Failed to load root" ) from e
167
+ raise exceptions .MetadataError ("Failed to load root" ) from e
168
168
169
169
if new_root .signed .type != Root .type :
170
- raise exceptions .RepositoryError (
170
+ raise exceptions .MetadataError (
171
171
f"Expected 'root', got '{ new_root .signed .type } '"
172
172
)
173
173
@@ -202,7 +202,7 @@ def update_timestamp(self, data: bytes) -> Metadata[Timestamp]:
202
202
data: unverified new timestamp metadata as bytes
203
203
204
204
Raises:
205
- RepositoryError : Metadata failed to load or verify as final
205
+ MetadataError : Metadata failed to load or verify as final
206
206
timestamp. The actual error type and content will contain
207
207
more details.
208
208
@@ -221,10 +221,10 @@ def update_timestamp(self, data: bytes) -> Metadata[Timestamp]:
221
221
try :
222
222
new_timestamp = Metadata [Timestamp ].from_bytes (data )
223
223
except DeserializationError as e :
224
- raise exceptions .RepositoryError ("Failed to load timestamp" ) from e
224
+ raise exceptions .MetadataError ("Failed to load timestamp" ) from e
225
225
226
226
if new_timestamp .signed .type != Timestamp .type :
227
- raise exceptions .RepositoryError (
227
+ raise exceptions .MetadataError (
228
228
f"Expected 'timestamp', got '{ new_timestamp .signed .type } '"
229
229
)
230
230
@@ -288,7 +288,7 @@ def update_snapshot(
288
288
match data. Default is False.
289
289
290
290
Raises:
291
- RepositoryError : data failed to load or verify as final snapshot.
291
+ MetadataError : data failed to load or verify as final snapshot.
292
292
The actual error type and content will contain more details.
293
293
294
294
Returns:
@@ -312,17 +312,17 @@ def update_snapshot(
312
312
try :
313
313
snapshot_meta .verify_length_and_hashes (data )
314
314
except exceptions .LengthOrHashMismatchError as e :
315
- raise exceptions .RepositoryError (
315
+ raise exceptions .MetadataError (
316
316
"Snapshot length or hashes do not match"
317
317
) from e
318
318
319
319
try :
320
320
new_snapshot = Metadata [Snapshot ].from_bytes (data )
321
321
except DeserializationError as e :
322
- raise exceptions .RepositoryError ("Failed to load snapshot" ) from e
322
+ raise exceptions .MetadataError ("Failed to load snapshot" ) from e
323
323
324
324
if new_snapshot .signed .type != Snapshot .type :
325
- raise exceptions .RepositoryError (
325
+ raise exceptions .MetadataError (
326
326
f"Expected 'snapshot', got '{ new_snapshot .signed .type } '"
327
327
)
328
328
@@ -338,7 +338,7 @@ def update_snapshot(
338
338
339
339
# Prevent removal of any metadata in meta
340
340
if new_fileinfo is None :
341
- raise exceptions .RepositoryError (
341
+ raise exceptions .MetadataError (
342
342
f"New snapshot is missing info for '{ filename } '"
343
343
)
344
344
@@ -381,7 +381,7 @@ def update_targets(self, data: bytes) -> Metadata[Targets]:
381
381
data: unverified new targets metadata as bytes
382
382
383
383
Raises:
384
- RepositoryError : Metadata failed to load or verify. The actual
384
+ MetadataError : Metadata failed to load or verify. The actual
385
385
error type and content will contain more details.
386
386
387
387
Returns:
@@ -400,7 +400,7 @@ def update_delegated_targets(
400
400
delegator_name: The name of the role delegating to the new metadata
401
401
402
402
Raises:
403
- RepositoryError : Metadata failed to load or verify. The actual
403
+ MetadataError : Metadata failed to load or verify. The actual
404
404
error type and content will contain more details.
405
405
406
406
Returns:
@@ -422,24 +422,24 @@ def update_delegated_targets(
422
422
# Verify against the hashes in snapshot, if any
423
423
meta = self .snapshot .signed .meta .get (f"{ role_name } .json" )
424
424
if meta is None :
425
- raise exceptions .RepositoryError (
425
+ raise exceptions .MetadataError (
426
426
f"Snapshot does not contain information for '{ role_name } '"
427
427
)
428
428
429
429
try :
430
430
meta .verify_length_and_hashes (data )
431
431
except exceptions .LengthOrHashMismatchError as e :
432
- raise exceptions .RepositoryError (
432
+ raise exceptions .MetadataError (
433
433
f"{ role_name } length or hashes do not match"
434
434
) from e
435
435
436
436
try :
437
437
new_delegate = Metadata [Targets ].from_bytes (data )
438
438
except DeserializationError as e :
439
- raise exceptions .RepositoryError ("Failed to load snapshot" ) from e
439
+ raise exceptions .MetadataError ("Failed to load snapshot" ) from e
440
440
441
441
if new_delegate .signed .type != Targets .type :
442
- raise exceptions .RepositoryError (
442
+ raise exceptions .MetadataError (
443
443
f"Expected 'targets', got '{ new_delegate .signed .type } '"
444
444
)
445
445
@@ -468,10 +468,10 @@ def _load_trusted_root(self, data: bytes) -> None:
468
468
try :
469
469
new_root = Metadata [Root ].from_bytes (data )
470
470
except DeserializationError as e :
471
- raise exceptions .RepositoryError ("Failed to load root" ) from e
471
+ raise exceptions .MetadataError ("Failed to load root" ) from e
472
472
473
473
if new_root .signed .type != Root .type :
474
- raise exceptions .RepositoryError (
474
+ raise exceptions .MetadataError (
475
475
f"Expected 'root', got '{ new_root .signed .type } '"
476
476
)
477
477
0 commit comments