Skip to content

Commit 1f0854f

Browse files
sechkovaMVrachev
authored andcommitted
Improve comments
Remove outdated comments. Add explanations to non-obvious cases. Signed-off-by: Teodora Sechkova <tsechkova@vmware.com>
1 parent 703614d commit 1f0854f

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
@@ -254,7 +254,6 @@ def update_timestamp(self, data: bytes):
254254
error type and content will contain more details.
255255
"""
256256
if not self._root_update_finished:
257-
# root_update_finished() not called
258257
raise RuntimeError("Cannot update timestamp before root")
259258
if self.snapshot is not None:
260259
raise RuntimeError("Cannot update timestamp after snapshot")
@@ -274,6 +273,8 @@ def update_timestamp(self, data: bytes):
274273
"New timestamp is not signed by root", new_timestamp.signed
275274
)
276275

276+
# If an existing trusted timestamp is updated,
277+
# check for a rollback attack
277278
if self.timestamp is not None:
278279
# Prevent rolling back timestamp version
279280
if new_timestamp.signed.version < self.timestamp.signed.version:
@@ -287,7 +288,6 @@ def update_timestamp(self, data: bytes):
287288
new_timestamp.signed.meta["snapshot.json"].version
288289
< self.timestamp.signed.meta["snapshot.json"].version
289290
):
290-
# TODO not sure about the correct exception here
291291
raise exceptions.ReplayedMetadataError(
292292
"snapshot",
293293
new_timestamp.signed.meta["snapshot.json"].version,
@@ -327,7 +327,6 @@ def update_snapshot(self, data: bytes): # pylint: disable=too-many-branches
327327
digest_object.update(data)
328328
observed_hash = digest_object.hexdigest()
329329
if observed_hash != stored_hash:
330-
# TODO: Error should derive from RepositoryError
331330
raise exceptions.BadHashError(stored_hash, observed_hash)
332331

333332
try:
@@ -355,6 +354,8 @@ def update_snapshot(self, data: bytes): # pylint: disable=too-many-branches
355354
f"got {new_snapshot.signed.version}"
356355
)
357356

357+
# If an existing trusted snapshot is updated,
358+
# check for a rollback attack
358359
if self.snapshot:
359360
for filename, fileinfo in self.snapshot.signed.meta.items():
360361
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)