Skip to content

Commit 46a8bd4

Browse files
committed
Improve comments
Remove outdated comments. Add explanations to non-obvious cases. Signed-off-by: Teodora Sechkova <[email protected]>
1 parent 97b0938 commit 46a8bd4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

tuf/ngclient/_internal/metadata_bundle.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ def update_timestamp(self, data: bytes):
257257
error type and content will contain more details.
258258
"""
259259
if not self._root_update_finished:
260-
# root_update_finished() not called
261260
raise RuntimeError("Cannot update timestamp before root")
262261
if self.snapshot is not None:
263262
raise RuntimeError("Cannot update timestamp after snapshot")
@@ -277,6 +276,8 @@ def update_timestamp(self, data: bytes):
277276
"New timestamp is not signed by root", new_timestamp.signed
278277
)
279278

279+
# If an existing trusted timestamp is updated,
280+
# check for a rollback attack
280281
if self.timestamp is not None:
281282
# Prevent rolling back timestamp version
282283
if new_timestamp.signed.version < self.timestamp.signed.version:
@@ -290,7 +291,6 @@ def update_timestamp(self, data: bytes):
290291
new_timestamp.signed.meta["snapshot.json"].version
291292
< self.timestamp.signed.meta["snapshot.json"].version
292293
):
293-
# TODO not sure about the correct exception here
294294
raise exceptions.ReplayedMetadataError(
295295
"snapshot",
296296
new_timestamp.signed.meta["snapshot.json"].version,
@@ -330,7 +330,6 @@ def update_snapshot(self, data: bytes): # pylint: disable=too-many-branches
330330
digest_object.update(data)
331331
observed_hash = digest_object.hexdigest()
332332
if observed_hash != stored_hash:
333-
# TODO: Error should derive from RepositoryError
334333
raise exceptions.BadHashError(stored_hash, observed_hash)
335334

336335
try:
@@ -358,6 +357,8 @@ def update_snapshot(self, data: bytes): # pylint: disable=too-many-branches
358357
f"got {new_snapshot.signed.version}"
359358
)
360359

360+
# If an existing trusted snapshot is updated,
361+
# check for a rollback attack
361362
if self.snapshot:
362363
for filename, fileinfo in self.snapshot.signed.meta.items():
363364
new_fileinfo = new_snapshot.signed.meta.get(filename)

tuf/ngclient/updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def updated_targets(targets: Dict, destination_directory: str) -> Dict:
122122
After the client has retrieved the target information for those targets
123123
they are interested in updating, they would call this method to
124124
determine which targets have changed from those saved locally on disk.
125-
All the targets that have changed are returns in a list. From this
125+
All the targets that have changed are returned in a list. From this
126126
list, they can request a download by calling 'download_target()'.
127127
"""
128128
# Keep track of the target objects and filepaths of updated targets.

0 commit comments

Comments
 (0)