Skip to content

Commit 345978c

Browse files
committed
rename mixin classes to better match their responsibility
1 parent cbf451d commit 345978c

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Lib/test/test_hmac.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def hmac_digest(self, key, msg=None, digestmod=None):
138138
return self.hmac.compute_digest(key, msg, digest=digestmod)
139139

140140

141-
class CheckerMixin:
141+
class ObjectCheckerMixin:
142142
"""Mixin for checking HMAC objects (pure Python, OpenSSL or built-in)."""
143143

144144
def check_object(self, h, hexdigest, hashname, digest_size, block_size):
@@ -159,7 +159,7 @@ def check_hexdigest(self, h, hexdigest, digest_size):
159159
self.assertEqual(h.hexdigest().upper(), hexdigest.upper())
160160

161161

162-
class TestVectorsMixin(CreatorMixin, DigestMixin, CheckerMixin):
162+
class AssertersMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
163163
"""Mixin class for common tests."""
164164

165165
def hmac_new_by_name(self, key, msg=None, *, hashname):
@@ -318,7 +318,7 @@ def assert_hmac_extra_cases(
318318
self.check_object(h1, hexdigest, hashname, digest_size, block_size)
319319

320320

321-
class PyTestVectorsMixin(PyModuleMixin, TestVectorsMixin):
321+
class PyAssertersMixin(PyModuleMixin, AssertersMixin):
322322

323323
def assert_hmac_extra_cases(
324324
self, key, msg, hexdigest, digestmod, hashname, digest_size, block_size
@@ -332,7 +332,7 @@ def assert_hmac_extra_cases(
332332
self.check_object(h, hexdigest, hashname, digest_size, block_size)
333333

334334

335-
class OpenSSLTestVectorsMixin(ThroughOpenSSLAPIMixin, TestVectorsMixin):
335+
class OpenSSLAssertersMixin(ThroughOpenSSLAPIMixin, AssertersMixin):
336336

337337
def hmac_new_by_name(self, key, msg=None, *, hashname):
338338
self.assertIsInstance(hashname, str)
@@ -345,7 +345,7 @@ def hmac_digest_by_name(self, key, msg=None, *, hashname):
345345
return self.hmac_digest(key, msg, digestmod=openssl_func)
346346

347347

348-
class BuiltinAssertersMixin(ThroughBuiltinAPIMixin, TestVectorsMixin):
348+
class BuiltinAssertersMixin(ThroughBuiltinAPIMixin, AssertersMixin):
349349
pass
350350

351351

@@ -390,7 +390,7 @@ def setUpClass(cls):
390390
setattr(cls, name, name)
391391

392392

393-
class RFCTestCasesMixin(HashFunctionsTrait):
393+
class RFCTestCaseMixin(HashFunctionsTrait):
394394
"""Test HMAC implementations against test vectors from the RFC."""
395395

396396
def test_md5(self):
@@ -472,7 +472,6 @@ def test_sha2_512_rfc4231(self):
472472
self._test_sha2_rfc4231(self.sha512, 'sha512', 64, 128)
473473

474474
def _test_sha2_rfc4231(self, hashfunc, hashname, digest_size, block_size):
475-
476475
def hmactest(key, data, hexdigests):
477476
hexdigest = hexdigests[hashname]
478477

@@ -592,26 +591,26 @@ def hmactest(key, data, hexdigests):
592591
})
593592

594593

595-
class PyRFCTestCase(ThroughObjectMixin, PyTestVectorsMixin,
596-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
594+
class PyRFCTestCase(ThroughObjectMixin, PyAssertersMixin,
595+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
597596
unittest.TestCase):
598597
"""Python implementation of HMAC using hmac.HMAC().
599598
600599
The underlying hash functions are OpenSSL-based.
601600
"""
602601

603602

604-
class PyDotNewRFCTestCase(ThroughModuleAPIMixin, PyTestVectorsMixin,
605-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
603+
class PyDotNewRFCTestCase(ThroughModuleAPIMixin, PyAssertersMixin,
604+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
606605
unittest.TestCase):
607606
"""Python implementation of HMAC using hmac.new().
608607
609608
The underlying hash functions are OpenSSL-based.
610609
"""
611610

612611

613-
class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin,
614-
WithOpenSSLHashFunctions, RFCTestCasesMixin,
612+
class OpenSSLRFCTestCase(OpenSSLAssertersMixin,
613+
WithOpenSSLHashFunctions, RFCTestCaseMixin,
615614
unittest.TestCase):
616615
"""OpenSSL implementation of HMAC.
617616
@@ -620,7 +619,7 @@ class OpenSSLRFCTestCase(OpenSSLTestVectorsMixin,
620619

621620

622621
class BuiltinRFCTestCase(BuiltinAssertersMixin,
623-
WithNamedHashFunctions, RFCTestCasesMixin,
622+
WithNamedHashFunctions, RFCTestCaseMixin,
624623
unittest.TestCase):
625624
"""Built-in HACL* implementation of HMAC.
626625
@@ -689,7 +688,7 @@ def _invalid_digestmod_cases(self, func, key, msg, choices):
689688
return cases
690689

691690

692-
class ConstructorTestCaseMixin(CreatorMixin, DigestMixin, CheckerMixin):
691+
class ConstructorTestCaseMixin(CreatorMixin, DigestMixin, ObjectCheckerMixin):
693692
"""HMAC constructor tests based on HMAC-SHA-2/256."""
694693

695694
key = b"key"

0 commit comments

Comments
 (0)