Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update hmac from v3.14.3
  • Loading branch information
CPython Developers authored and youknowone committed Feb 15, 2026
commit 2a611c992d6a712a5a00399b31c16202d094471a
1 change: 1 addition & 0 deletions Lib/hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def copy(self):
# Call __new__ directly to avoid the expensive __init__.
other = self.__class__.__new__(self.__class__)
other.digest_size = self.digest_size
other.block_size = self.block_size
if self._hmac:
other._hmac = self._hmac.copy()
other._inner = other._outer = None
Expand Down
34 changes: 21 additions & 13 deletions Lib/test/test_hmac.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,14 @@ def test_hmac_digest_digestmod_parameter(self):
):
self.hmac_digest(b'key', b'msg', value)

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'. Did you mean: 'exc_type'?
def test_internal_types(self):
return super().test_internal_types()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'hmac_digest'
def test_digest(self):
return super().test_digest()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_constructor(self):
return super().test_constructor()
Expand All @@ -1078,14 +1086,6 @@ def test_constructor_missing_digestmod(self):
def test_constructor_unknown_digestmod(self):
return super().test_constructor_unknown_digestmod()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'. Did you mean: 'exc_type'?
def test_internal_types(self):
return super().test_internal_types()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'hmac_digest'
def test_digest(self):
return super().test_digest()


class BuiltinConstructorTestCase(ThroughBuiltinAPIMixin,
ExtensionConstructorTestCaseMixin,
Expand Down Expand Up @@ -1137,6 +1137,15 @@ def test_properties(self):
self.assertEqual(h.digest_size, self.digest_size)
self.assertEqual(h.block_size, self.block_size)

def test_copy(self):
# Test a generic copy() and the attributes it exposes.
# See https://github.com/python/cpython/issues/142451.
h1 = self.hmac_new(b"my secret key", digestmod=self.digestname)
h2 = h1.copy()
self.assertEqual(h1.name, h2.name)
self.assertEqual(h1.digest_size, h2.digest_size)
self.assertEqual(h1.block_size, h2.block_size)

def test_repr(self):
# HMAC object representation may differ across implementations
raise NotImplementedError
Expand All @@ -1160,7 +1169,6 @@ def test_repr(self):


@hashlib_helper.requires_openssl_hashdigest('sha256')
@unittest.skip("TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute 'HMAC'")
class OpenSSLSanityTestCase(ThroughOpenSSLAPIMixin, SanityTestCaseMixin,
unittest.TestCase):

Expand Down Expand Up @@ -1257,10 +1265,6 @@ def HMAC(self, key, msg=None):
def gil_minsize(self):
return _hashlib._GIL_MINSIZE

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_update(self):
return super().test_update()

@unittest.expectedFailure # TODO: RUSTPYTHON; AttributeError: module '_hashlib' has no attribute '_GIL_MINSIZE'
def test_update_large(self):
return super().test_update_large()
Expand All @@ -1269,6 +1273,10 @@ def test_update_large(self):
def test_update_exceptions(self):
return super().test_update_exceptions()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_update(self):
return super().test_update()


class BuiltinUpdateTestCase(BuiltinModuleMixin,
UpdateTestCaseMixin, unittest.TestCase):
Expand Down