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