File tree Expand file tree Collapse file tree 3 files changed +14
-0
lines changed
Expand file tree Collapse file tree 3 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ def copy(self):
127127 # Call __new__ directly to avoid the expensive __init__.
128128 other = self .__class__ .__new__ (self .__class__ )
129129 other .digest_size = self .digest_size
130+ other .block_size = self .block_size
130131 if self ._hmac :
131132 other ._hmac = self ._hmac .copy ()
132133 other ._inner = other ._outer = None
Original file line number Diff line number Diff line change @@ -489,6 +489,16 @@ def test_with_str_update(self):
489489
490490class CopyTestCase (unittest .TestCase ):
491491
492+ @hashlib_helper .requires_hashdigest ('sha256' )
493+ def test_copy (self ):
494+ # Test a generic copy() and the attributes it exposes.
495+ # See https://github.com/python/cpython/issues/142451.
496+ h1 = hmac .new (b"my secret key" , digestmod = "sha256" )
497+ h2 = h1 .copy ()
498+ self .assertEqual (h1 .name , h2 .name )
499+ self .assertEqual (h1 .digest_size , h2 .digest_size )
500+ self .assertEqual (h1 .block_size , h2 .block_size )
501+
492502 @hashlib_helper .requires_hashdigest ('sha256' )
493503 def test_attributes_old (self ):
494504 # Testing if attributes are of same type.
Original file line number Diff line number Diff line change 1+ :mod: `hmac `: Ensure that the :attr: `HMAC.block_size <hmac.HMAC.block_size> `
2+ attribute is correctly copied by :meth: `HMAC.copy <hmac.HMAC.copy> `. Patch
3+ by Bénédikt Tran.
You can’t perform that action at this time.
0 commit comments