Skip to content

Commit 8cd3fb5

Browse files
committed
update comments
- update comments for `CreatorMixin.hmac_new()` - update comments for `DigestMixin.hmac_digest()` - update comments for `TestVectorsMixin` - update comments for `TestVectorsMixin.hmac_new_by_name()` - update comments for `TestVectorsMixin.hmac_digest_by_name()`
1 parent e20c2d1 commit 8cd3fb5

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Lib/test/test_hmac.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ class CreatorMixin:
6161
"""Mixin exposing a method creating a HMAC object."""
6262

6363
def hmac_new(self, key, msg=None, digestmod=None):
64-
"""Create a new HMAC object."""
64+
"""Create a new HMAC object.
65+
66+
Implementations should accept arbitrary 'digestmod' as this
67+
method can be used to test which exceptions are being raised.
68+
"""
6569
raise NotImplementedError
6670

6771
def bind_hmac_new(self, digestmod):
@@ -73,7 +77,11 @@ class DigestMixin:
7377
"""Mixin exposing a method computing a HMAC digest."""
7478

7579
def hmac_digest(self, key, msg=None, digestmod=None):
76-
"""Compute a HMAC digest."""
80+
"""Compute a HMAC digest.
81+
82+
Implementations should accept arbitrary 'digestmod' as this
83+
method can be used to test which exceptions are being raised.
84+
"""
7785
raise NotImplementedError
7886

7987
def bind_hmac_digest(self, digestmod):
@@ -142,7 +150,7 @@ def check_hexdigest(self, h, hexdigest, digest_size):
142150

143151

144152
class TestVectorsMixin(CreatorMixin, DigestMixin, CheckerMixin):
145-
"""Mixin class for all test vectors test cases."""
153+
"""Mixin class for common tests."""
146154

147155
def hmac_new_by_name(self, key, msg=None, hashname=None):
148156
"""Alternative implementation of hmac_new().
@@ -152,13 +160,23 @@ def hmac_new_by_name(self, key, msg=None, hashname=None):
152160
by their name (all HMAC implementations must at least recognize
153161
hash functions by their names but some may use aliases such as
154162
`hashlib.sha1` instead of "sha1").
163+
164+
Unlike hmac_new(), this method may assert the type of 'hashname'
165+
as it should only be used in tests that are expected to create
166+
a HMAC object.
155167
"""
156168
self.assertIsInstance(hashname, str | None)
157169
return self.hmac_new(key, msg, digestmod=hashname)
158170

159171
def hmac_digest_by_name(self, key, msg=None, hashname=None):
160172
"""Alternative implementation of hmac_digest()."""
161173
self.assertIsInstance(hashname, str | None)
174+
"""Alternative implementation of hmac_digest().
175+
176+
Unlike hmac_digest(), this method may assert the type of 'hashname'
177+
as it should only be used in tests that are expected to compute a
178+
HMAC digest.
179+
"""
162180
return self.hmac_digest(key, msg, digestmod=hashname)
163181

164182
def assert_hmac(

0 commit comments

Comments
 (0)