@@ -1167,11 +1167,7 @@ def neither_403_nor_404(mirror_error):
11671167 def _check_hashes (self , file_object , trusted_hashes ):
11681168 """
11691169 <Purpose>
1170- Non-public method that verifies multiple secure hashes of the downloaded
1171- file 'file_object'. If any of these fail it raises an exception. This is
1172- to conform with the TUF spec, which support clients with different hashing
1173- algorithms. The 'hash.py' module is used to compute the hashes of
1174- 'file_object'.
1170+ Non-public method that verifies multiple secure hashes of 'file_object'.
11751171
11761172 <Arguments>
11771173 file_object:
@@ -1193,25 +1189,18 @@ def _check_hashes(self, file_object, trusted_hashes):
11931189 None.
11941190 """
11951191
1196- # Verify each trusted hash of 'trusted_hashes'. If all are valid, simply
1197- # return.
1192+ # Verify each hash, raise an exception if any hash fails to verify
11981193 for algorithm , trusted_hash in six .iteritems (trusted_hashes ):
1199- digest_object = securesystemslib .hash .digest (algorithm )
1200- # Ensure we read from the beginning of the file object
1201- # TODO: should we store file position (before the loop) and reset after we
1202- # seek about?
1203- file_object .seek (0 )
1204- digest_object .update (file_object .read ())
1194+ digest_object = securesystemslib .hash .digest_fileobject (file_object ,
1195+ algorithm )
12051196 computed_hash = digest_object .hexdigest ()
12061197
1207- # Raise an exception if any of the hashes are incorrect.
12081198 if trusted_hash != computed_hash :
12091199 raise securesystemslib .exceptions .BadHashError (trusted_hash ,
12101200 computed_hash )
12111201
12121202 else :
1213- logger .info ('The file\' s ' + algorithm + ' hash is'
1214- ' correct: ' + trusted_hash )
1203+ logger .info ('Verified ' + algorithm + ' hash: ' + trusted_hash )
12151204
12161205
12171206
0 commit comments