This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author kteague
Recipients kteague
Date 2009-02-16.23:34:06
SpamBayes Score 1.9494546e-09
Marked as misclassified No
Message-id <1234827307.61.0.0730804396483.issue5285@psf.upfronthosting.co.za>
In-reply-to
Content
In Python 2.6 a performance optimization was added to the hmac module
(http://bugs.python.org/issue1618455). This appears to have the
unintended consequence of no longer accepting unicode strings as input.

Python 2.5.1 (r251:54863, Feb  4 2008, 21:48:13) 
>>> import hmac
>>> hmac.new(u'key','msg')
<hmac.HMAC instance at 0x6e440>

Python 2.6.1 (r261:67515, Dec  9 2008, 14:49:30) 
>>> import hmac
>>> hmac.new(u'key','msg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/Users/kteague/buildouts/shared/python-2.6.1/lib/python2.6/hmac.py",
line 133, in new
    return HMAC(key, msg, digestmod)
  File
"/Users/kteague/buildouts/shared/python-2.6.1/lib/python2.6/hmac.py",
line 72, in __init__
    self.outer.update(key.translate(trans_5C))
TypeError: character mapping must return integer, None or unicode

This change is also reflected in Python 3.0 as the hmac module only
accepts data as input (althought the docs still mention 'strings').

Python 3.0.1 (r301:69556, Feb 16 2009, 14:38:14) 
>>> import hmac
>>> hmac.new('key','msg')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/Users/kteague/buildouts/shared/python-3.0.1/lib/python3.0/hmac.py",
line 140, in new
    return HMAC(key, msg, digestmod)
  File
"/Users/kteague/buildouts/shared/python-3.0.1/lib/python3.0/hmac.py",
line 43, in __init__
    raise TypeError("expected bytes, but got %r" % type(key).__name__)
TypeError: expected bytes, but got 'str'
>>> hmac.new(b'key',b'msg')
<hmac.HMAC object at 0x3a1810>

This module should likely accept both string and unicode (Python 2) or
text and data (Python 3) and handle the conversion internally?
History
Date User Action Args
2009-02-16 23:35:08kteaguesetrecipients: + kteague
2009-02-16 23:35:07kteaguesetmessageid: <1234827307.61.0.0730804396483.issue5285@psf.upfronthosting.co.za>
2009-02-16 23:34:07kteaguelinkissue5285 messages
2009-02-16 23:34:06kteaguecreate