@@ -1501,17 +1501,36 @@ def update(self, v):
15011501 self ._x .update (v )
15021502 def digest (self ):
15031503 return self ._x .digest ()
1504+ def copy (self ):
1505+ h = MockCrazyHash ()
1506+ h ._x = self ._x .copy ()
1507+ return h
15041508
15051509 with warnings .catch_warnings ():
15061510 warnings .simplefilter ('error' , RuntimeWarning )
15071511 with self .assertRaises (RuntimeWarning ):
15081512 hmac .HMAC (b'a' , b'b' , digestmod = MockCrazyHash )
15091513 self .fail ('Expected warning about missing block_size' )
1514+ with self .assertRaises (RuntimeWarning ):
1515+ hmac .digest (b'a' , b'b' , MockCrazyHash )
1516+ self .fail ('Expected warning about missing block_size' )
15101517
15111518 MockCrazyHash .block_size = 1
15121519 with self .assertRaises (RuntimeWarning ):
15131520 hmac .HMAC (b'a' , b'b' , digestmod = MockCrazyHash )
15141521 self .fail ('Expected warning about small block_size' )
1522+ with self .assertRaises (RuntimeWarning ):
1523+ hmac .digest (b'a' , b'b' , MockCrazyHash )
1524+ self .fail ('Expected warning about small block_size' )
1525+
1526+ # gh-155428: hmac.HMAC() and hmac.digest() must both
1527+ # fall back to the default block size (64 for SHA-256).
1528+ expect = hmac .digest (b'a' , b'b' , 'sha256' )
1529+ with warnings .catch_warnings ():
1530+ warnings .simplefilter ('ignore' , RuntimeWarning )
1531+ h = hmac .HMAC (b'a' , b'b' , digestmod = MockCrazyHash )
1532+ self .assertEqual (h .digest (), expect )
1533+ self .assertEqual (hmac .digest (b'a' , b'b' , MockCrazyHash ), expect )
15151534
15161535 @hashlib_helper .requires_hashdigest ('sha256' )
15171536 def test_with_fallback (self ):
0 commit comments