Issue 18240: hmac unnecessarily restricts input to "bytes" (original) (raw)

Created on 2013-06-17 10:38 by jborgstrom, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
hmac.patch jborgstrom,2013-06-17 20:18 Proposed patch review
hmac2.patch jborgstrom,2013-06-18 10:49 Updated patch review
Messages (10)
msg191321 - (view) Author: Jonas Borgström (jborgstrom) * Date: 2013-06-17 10:38
Problem: In hmac.py there's a type check that verifies that the msg parameter is of type bytes(). if not isinstance(msg, bytes): raise TypeError("expected bytes, but got %r" % type(msg).__name__) That is incorrect. The hmac module should also work with other data types as long as they are supported by the underlying hashlib module, for example bytearray() and memoryview(). Suggestion: Remove that type check. hashlib will make sure str() and other invalid data types raises a TypeError.
msg191324 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-17 11:58
Good idea! We can also lift the restriction for ``key`` a bit. It can also take a bytearray as argument. bytearray has translate() and supports bytes + bytearay.
msg191374 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-17 20:37
Thanks for your patch! Please add tests for the new feature. The documentation needs versionchanged tags, too.
msg191395 - (view) Author: Jonas Borgström (jborgstrom) * Date: 2013-06-18 10:49
Patch updated to include tests and versionchanged tags
msg191396 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-18 11:40
Thanks for your update. As far as I can tell you haven't signed our contributor agreement yet. Can you please do so? http://www.python.org/psf/contrib/ http://www.python.org/psf/contrib/contrib-form/
msg191398 - (view) Author: Jonas Borgström (jborgstrom) * Date: 2013-06-18 11:48
Of course. I've now signed and filed the agreement.
msg191399 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-18 11:53
It may take a day or two until your signature makes it through red tape. I'll get back to you. :)
msg191757 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-06-24 12:26
Your account hasn't been flagged yet. I'm going to ping the person in charge.
msg192120 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-07-01 11:08
New changeset 636947fe131e by Christian Heimes in branch 'default': Issue 18240: The HMAC module is no longer restricted to bytes and accepts http://hg.python.org/cpython/rev/636947fe131e
msg192121 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-01 11:09
Your CLA came through and I have applied your patch. Thank you very much for your contribution!
History
Date User Action Args
2022-04-11 14:57:47 admin set github: 62440
2013-11-12 08:43:07 mpb set nosy: + mpb
2013-07-01 11:09:50 christian.heimes set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2013-07-01 11:08:56 python-dev set nosy: + python-devmessages: +
2013-06-24 12:26:21 christian.heimes set messages: +
2013-06-18 11:53:43 christian.heimes set messages: +
2013-06-18 11:48:20 jborgstrom set messages: +
2013-06-18 11:40:04 christian.heimes set messages: + stage: needs patch -> patch review
2013-06-18 10:49:30 jborgstrom set files: + hmac2.patchmessages: +
2013-06-17 20:37:03 christian.heimes set messages: +
2013-06-17 20🔞58 jborgstrom set files: + hmac.patchkeywords: + patch
2013-06-17 11:58:30 christian.heimes set assignee: christian.heimesmessages: +
2013-06-17 11:48:56 pitrou set nosy: + gregory.p.smith, christian.heimesstage: needs patchtype: behavior -> enhancementversions: + Python 3.4, - Python 3.3
2013-06-17 10:38:28 jborgstrom create