@@ -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 )
0 commit comments