Title: hmac unnecessarily restricts input to "bytes"
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: christian.heimes Nosy List: christian.heimes, gregory.p.smith, jborgstrom, mpb, python-dev
Priority: normal Keywords: patch

Created on 2013-06-17 10:38 by jborgstrom, last changed 2013-11-12 08:43 by mpb. This issue is now closed.

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
In 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().

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?
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) 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
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!
Date User Action Args
2013-11-12 08:43:07mpbsetnosy: + mpb
2013-07-01 11:09:50christian.heimessetstatus: open -> closed
resolution: fixed
messages: + msg192121

stage: patch review -> resolved
2013-07-01 11:08:56python-devsetnosy: + python-dev
messages: + msg192120
2013-06-24 12:26:21christian.heimessetmessages: + msg191757
2013-06-18 11:53:43christian.heimessetmessages: + msg191399
2013-06-18 11:48:20jborgstromsetmessages: + msg191398
2013-06-18 11:40:04christian.heimessetmessages: + msg191396
stage: needs patch -> patch review
2013-06-18 10:49:30jborgstromsetfiles: + hmac2.patch

messages: + msg191395
2013-06-17 20:37:03christian.heimessetmessages: + msg191374
2013-06-17 20:18:58jborgstromsetfiles: + hmac.patch
keywords: + patch
2013-06-17 11:58:30christian.heimessetassignee: christian.heimes
messages: + msg191324
2013-06-17 11:48:56pitrousetnosy: + gregory.p.smith, christian.heimes
stage: needs patch
type: behavior -> enhancement

versions: + Python 3.4, - Python 3.3
2013-06-17 10:38:28jborgstromcreate