Author CCLDArjun
Recipients CCLDArjun, iritkatriel
Date 2021-06-09.21:43:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1623275008.24.0.423356637016.issue14322@roundup.psfhosted.org>
In-reply-to
Content
The only things I think we should add to the current hmac tests are test_update_error_handling and test_with_invalid_msg. 

For test_withnoncallable_digestmod(), hmac itself seems it can no longer be used:

>>> hmac.HMAC(b"gggg", None, "hmac")
<module '_hashlib' from '/Users/arjun/Python/Sources/cpython/build/lib.macosx-11.4-x86_64-3.11-pydebug/_hashlib.cpython-311d-darwin.so'>
using new
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/arjun/Python/Sources/cpython/Lib/hmac.py", line 61, in __init__
    self._init_hmac(key, msg, digestmod)
  File "/Users/arjun/Python/Sources/cpython/Lib/hmac.py", line 69, in _init_hmac
    self._hmac = _hashopenssl.hmac_new(key, msg, digestmod=digestmod)
ValueError: unsupported hash type hmac

For tests test_small_block_size and test_no_block_size, a custom .blocksize cannot be set (changing .block_size has no difference on digest()):

>>> hmac.HMAC(b"gggg", None, "md5").blocksize = 15
<module '_hashlib' from '/Users/arjun/Python/Sources/cpython/build/lib.macosx-11.4-x86_64-3.11-pydebug/_hashlib.cpython-311d-darwin.so'>
using new
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'HMAC' object attribute 'blocksize' is read-only

```
class myHMAC(hmac.HMAC):
    blocksize = 1
    def __init__(self, key, msg, digestmod_):
        super().__init__(key, msg, digestmod=digestmod_)

h = myHMAC(b"key", b"", digestmod_="md5")
h.digest() # <- works perfectly fine.
```
Does this sound okay? I can go ahead an implement it if so.
History
Date User Action Args
2021-06-09 21:43:28CCLDArjunsetrecipients: + CCLDArjun, iritkatriel
2021-06-09 21:43:28CCLDArjunsetmessageid: <1623275008.24.0.423356637016.issue14322@roundup.psfhosted.org>
2021-06-09 21:43:28CCLDArjunlinkissue14322 messages
2021-06-09 21:43:27CCLDArjuncreate