File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ def test_hash_manager():
214
214
assert hasher .hexdigest () == TWINE_1_5_0_WHEEL_HEXDIGEST
215
215
216
216
217
- def test_fips_hash_manager (monkeypatch ):
217
+ def test_fips_hash_manager_md5 (monkeypatch ):
218
218
"""Generate hexdigest without MD5 when hashlib is using FIPS mode."""
219
219
replaced_md5 = pretend .raiser (ValueError ("fipsmode" ))
220
220
monkeypatch .setattr (package_file .hashlib , "md5" , replaced_md5 )
@@ -226,6 +226,18 @@ def test_fips_hash_manager(monkeypatch):
226
226
assert hasher .hexdigest () == hashes
227
227
228
228
229
+ def test_fips_hash_manager_blake2 (monkeypatch ):
230
+ """Generate hexdigest without BLAKE2 when hashlib is using FIPS mode."""
231
+ replaced_blake2b = pretend .raiser (ValueError ("fipsmode" ))
232
+ monkeypatch .setattr (package_file .hashlib , "blake2b" , replaced_blake2b )
233
+
234
+ filename = "tests/fixtures/twine-1.5.0-py2.py3-none-any.whl"
235
+ hasher = package_file .HashManager (filename )
236
+ hasher .hash ()
237
+ hashes = TWINE_1_5_0_WHEEL_HEXDIGEST ._replace (blake2 = None )
238
+ assert hasher .hexdigest () == hashes
239
+
240
+
229
241
def test_pkginfo_returns_no_metadata (monkeypatch ):
230
242
"""Raise an exception when pkginfo can't interpret the metadata.
231
243
Original file line number Diff line number Diff line change @@ -220,7 +220,12 @@ def __init__(self, filename: str) -> None:
220
220
221
221
self ._sha2_hasher = hashlib .sha256 ()
222
222
223
- self ._blake_hasher = hashlib .blake2b (digest_size = 256 // 8 )
223
+ self ._blake_hasher = None
224
+ try :
225
+ self ._blake_hasher = hashlib .blake2b (digest_size = 256 // 8 )
226
+ except ValueError :
227
+ # FIPS mode disables blake2
228
+ pass
224
229
225
230
def _md5_update (self , content : bytes ) -> None :
226
231
if self ._md5_hasher is not None :
You can’t perform that action at this time.
0 commit comments