@@ -1506,37 +1506,28 @@ def test_with_fallback(self):
1506
1506
@hashlib_helper .requires_openssl_hashdigest ("md5" )
1507
1507
@bigmemtest (size = _4G , memuse = 2 , dry_run = False )
1508
1508
def test_hmac_digest_overflow_error_openssl_only (self , size ):
1509
- self .do_test_hmac_digest_overflow_error_fast (size , openssl = True )
1509
+ hmac = import_fresh_module ("hmac" , blocked = ["_hmac" ])
1510
+ self .do_test_hmac_digest_overflow_error_switch_to_slow (hmac , size )
1510
1511
1511
1512
@hashlib_helper .requires_builtin_hashdigest ("_md5" , "md5" )
1512
1513
@bigmemtest (size = _4G , memuse = 2 , dry_run = False )
1513
1514
def test_hmac_digest_overflow_error_builtin_only (self , size ):
1514
- self .do_test_hmac_digest_overflow_error_fast (size , openssl = False )
1515
-
1516
- def do_test_hmac_digest_overflow_error_fast (self , size , * , openssl ):
1517
- """Check that C hmac.digest() works for large inputs."""
1518
-
1519
- if openssl :
1520
- hmac = import_fresh_module ("hmac" , blocked = ["_hashlib" ])
1521
- c_module_name , c_method_name = "_hmac" , "new"
1522
- else :
1523
- hmac = import_fresh_module ("hmac" , blocked = ["_hmac" ])
1524
- c_module_name , c_method_name = "_hashlib" , "hmac_new"
1515
+ hmac = import_fresh_module ("hmac" , blocked = ["_hashlib" ])
1516
+ self .do_test_hmac_digest_overflow_error_switch_to_slow (hmac , size )
1525
1517
1526
- cext = import_helper . import_module ( c_module_name )
1527
- cnew = getattr ( cext , c_method_name )
1518
+ def do_test_hmac_digest_overflow_error_switch_to_slow ( self , hmac , size ):
1519
+ """Check that hmac.digest() falls back to pure Python."""
1528
1520
1529
1521
bigkey = b'K' * size
1530
1522
bigmsg = b'M' * size
1531
1523
1532
1524
with patch .object (hmac , "_compute_digest_fallback" ) as slow :
1533
- with patch .object (cext , c_method_name , wraps = cnew ) as new :
1534
- self .assertIsInstance (hmac .digest (bigkey , b'm' , "md5" ), bytes )
1535
- new .assert_called_once ()
1536
- with patch .object (cext , c_method_name , wraps = cnew ) as new :
1537
- self .assertIsInstance (hmac .digest (b'k' , bigmsg , "md5" ), bytes )
1538
- new .assert_called_once ()
1539
- slow .assert_not_called ()
1525
+ self .assertIsInstance (hmac .digest (bigkey , b'm' , "md5" ), bytes )
1526
+ slow .assert_called_once ()
1527
+
1528
+ with patch .object (hmac , "_compute_digest_fallback" ) as slow :
1529
+ self .assertIsInstance (hmac .digest (b'k' , bigmsg , "md5" ), bytes )
1530
+ slow .assert_called_once ()
1540
1531
1541
1532
@hashlib_helper .requires_hashdigest ("md5" , openssl = True )
1542
1533
@bigmemtest (size = _4G , memuse = 2 , dry_run = False )
0 commit comments