File tree Expand file tree Collapse file tree 3 files changed +13
-0
lines changed
Expand file tree Collapse file tree 3 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -159,6 +159,7 @@ def copy(self):
159159 # Call __new__ directly to avoid the expensive __init__.
160160 other = self .__class__ .__new__ (self .__class__ )
161161 other .digest_size = self .digest_size
162+ other .block_size = self .block_size
162163 if self ._hmac :
163164 other ._hmac = self ._hmac .copy ()
164165 other ._inner = other ._outer = None
Original file line number Diff line number Diff line change @@ -1076,6 +1076,15 @@ def test_properties(self):
10761076 self .assertEqual (h .digest_size , self .digest_size )
10771077 self .assertEqual (h .block_size , self .block_size )
10781078
1079+ def test_copy (self ):
1080+ # Test a generic copy() and the attributes it exposes.
1081+ # See https://github.com/python/cpython/issues/142451.
1082+ h1 = self .hmac_new (b"my secret key" , digestmod = self .digestname )
1083+ h2 = h1 .copy ()
1084+ self .assertEqual (h1 .name , h2 .name )
1085+ self .assertEqual (h1 .digest_size , h2 .digest_size )
1086+ self .assertEqual (h1 .block_size , h2 .block_size )
1087+
10791088 def test_repr (self ):
10801089 # HMAC object representation may differ across implementations
10811090 raise NotImplementedError
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