Skip to content

Commit 8c88360

Browse files
committed
rename mixin classes to better match their responsibility
1 parent bc48eac commit 8c88360

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

Lib/test/test_hmac.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def hmac_digest(self, key, msg=None, digestmod=None):
128128
return _hashlib.hmac_digest(key, msg, digest=digestmod)
129129

130130

131-
class CheckerMixin:
131+
class ObjectCheckerMixin:
132132
"""Mixin for checking HMAC objects (pure Python, OpenSSL or built-in)."""
133133

134134
def check_object(self, h, hexdigest, hashname, digest_size, block_size):
@@ -149,7 +149,7 @@ def check_hexdigest(self, h, hexdigest, digest_size):
149149
self.assertEqual(h.hexdigest().upper(), hexdigest.upper())
150150

151151

152-
class TestVectorsMixin(CreatorMixin, DigestMixin, CheckerMixin):
152+
class AssertersMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
153153
"""Mixin class for common tests."""
154154

155155
def hmac_new_by_name(self, key, msg=None, *, hashname):
@@ -308,7 +308,7 @@ def assert_hmac_extra_cases(
308308
self.check_object(h1, hexdigest, hashname, digest_size, block_size)
309309

310310

311-
class PyTestVectorsMixin(PyModuleMixin, TestVectorsMixin):
311+
class PyAssertersMixin(PyModuleMixin, AssertersMixin):
312312

313313
def assert_hmac_extra_cases(
314314
self, key, msg, hexdigest, digestmod, hashname, digest_size, block_size
@@ -322,7 +322,7 @@ def assert_hmac_extra_cases(
322322
self.check_object(h, hexdigest, hashname, digest_size, block_size)
323323

324324

325-
class OpenSSLTestVectorsMixin(ThroughOpenSSLAPIMixin, TestVectorsMixin):
325+
class OpenSSLAssertersMixin(ThroughOpenSSLAPIMixin, AssertersMixin):
326326

327327
def hmac_new_by_name(self, key, msg=None, *, hashname):
328328
self.assertIsInstance(hashname, str)
@@ -376,7 +376,7 @@ def setUpClass(cls):
376376
setattr(cls, name, name)
377377

378378

379-
class RFCTestCasesMixin(HashFunctionsTrait):
379+
class RFCTestCaseMixin(HashFunctionsTrait):
380380
"""Test HMAC implementations against test vectors from the RFC."""
381381

382382
def test_md5(self):
@@ -458,7 +458,6 @@ def test_sha2_512_rfc4231(self):
458458
self._test_sha2_rfc4231(self.sha512, 'sha512', 64, 128)
459459

460460
def _test_sha2_rfc4231(self, hashfunc, hashname, digest_size, block_size):
461-
462461
def hmactest(key, data, hexdigests):
463462
hexdigest = hexdigests[hashname]
464463

@@ -578,34 +577,33 @@ def hmactest(key, data, hexdigests):
578577
})
579578

580579

581-
class PyRFCTestCase(ThroughObjectMixin, PyTestVectorsMixin,
582-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
580+
class PyRFCTestCase(ThroughObjectMixin, PyAssertersMixin,
581+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
583582
unittest.TestCase):
584583
"""Python implementation of HMAC using hmac.HMAC().
585584
586585
The underlying hash functions are OpenSSL-based.
587586
"""
588587

589588

590-
class PyDotNewRFCTestCase(ThroughModuleAPIMixin, PyTestVectorsMixin,
591-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
589+
class PyDotNewRFCTestCase(ThroughModuleAPIMixin, PyAssertersMixin,
590+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
592591
unittest.TestCase):
593592
"""Python implementation of HMAC using hmac.new().
594593
595594
The underlying hash functions are OpenSSL-based.
596595
"""
597596

598597

599-
class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin,
600-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
598+
class OpenSSLRFCTestCase(OpenSSLAssertersMixin,
599+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
601600
unittest.TestCase):
602601
"""OpenSSL implementation of HMAC.
603602
604603
The underlying hash functions are also OpenSSL-based.
605604
"""
606605

607606

608-
609607
# TODO(picnixz): once we have a HACL* HMAC, we should also test the Python
610608
# implementation of HMAC with a HACL*-based hash function. For now, we only
611609
# test it partially via the '_sha2' module, but for completeness we could
@@ -668,7 +666,7 @@ def _invalid_digestmod_cases(self, func, key, msg, choices):
668666
return cases
669667

670668

671-
class ConstructorTestCaseMixin(CreatorMixin, DigestMixin, CheckerMixin):
669+
class ConstructorTestCaseMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
672670
"""HMAC constructor tests based on HMAC-SHA-2/256."""
673671

674672
key = b"key"

0 commit comments

Comments
 (0)