@@ -679,12 +679,20 @@ def _verify_hashes(
679
679
"""Verifies that the hash of 'data' matches 'expected_hashes'"""
680
680
is_bytes = isinstance (data , bytes )
681
681
for algo , exp_hash in expected_hashes .items ():
682
- if is_bytes :
683
- digest_object = sslib_hash .digest (algo )
684
- digest_object .update (data )
685
- else :
686
- # if data is not bytes, assume it is a file object
687
- digest_object = sslib_hash .digest_fileobject (data , algo )
682
+ try :
683
+ if is_bytes :
684
+ digest_object = sslib_hash .digest (algo )
685
+ digest_object .update (data )
686
+ else :
687
+ # if data is not bytes, assume it is a file object
688
+ digest_object = sslib_hash .digest_fileobject (data , algo )
689
+ except (
690
+ sslib_exceptions .UnsupportedAlgorithmError ,
691
+ sslib_exceptions .FormatError ,
692
+ ) as e :
693
+ raise exceptions .LengthOrHashMismatchError (
694
+ f"Unsupported algorithm '{ algo } '"
695
+ ) from e
688
696
689
697
observed_hash = digest_object .hexdigest ()
690
698
if observed_hash != exp_hash :
@@ -797,7 +805,7 @@ def verify_length_and_hashes(self, data: Union[bytes, BinaryIO]):
797
805
data: File object or its content in bytes.
798
806
Raises:
799
807
LengthOrHashMismatchError: Calculated length or hashes do not
800
- match expected values.
808
+ match expected values or hash algorithm is not supported .
801
809
"""
802
810
if self .length is not None :
803
811
self ._verify_length (data , self .length )
@@ -1094,7 +1102,7 @@ def verify_length_and_hashes(self, data: Union[bytes, BinaryIO]):
1094
1102
data: File object or its content in bytes.
1095
1103
Raises:
1096
1104
LengthOrHashMismatchError: Calculated length or hashes do not
1097
- match expected values.
1105
+ match expected values or hash algorithm is not supported .
1098
1106
"""
1099
1107
self ._verify_length (data , self .length )
1100
1108
self ._verify_hashes (data , self .hashes )
0 commit comments