aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorAyrx <terrycwk1994@gmail.com>2014-05-17 16:59:31 +0800
committerAyrx <terrycwk1994@gmail.com>2014-05-17 16:59:31 +0800
commit6d69eab6caff7b87d32fab3c7178296e481eb8a4 (patch)
treeb421709339ac20068fba14dc64cc062031b9ed1f /cryptography/hazmat/primitives/hmac.py
parent60437c370d079d55db2c284e2f241ecde3b61cbf (diff)
downloadcryptography-6d69eab6caff7b87d32fab3c7178296e481eb8a4.tar.gz
cryptography-6d69eab6caff7b87d32fab3c7178296e481eb8a4.tar.bz2
cryptography-6d69eab6caff7b87d32fab3c7178296e481eb8a4.zip
Fixed TypeError and added documentation
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r--cryptography/hazmat/primitives/hmac.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index afbb2f75..e39fcf89 100644
--- a/cryptography/hazmat/primitives/hmac.py
+++ b/cryptography/hazmat/primitives/hmac.py
@@ -46,8 +46,11 @@ class HMAC(object):
def update(self, msg):
if self._ctx is None:
raise AlreadyFinalized("Context was already finalized")
- if isinstance(msg, six.text_type):
- raise TypeError("Unicode-objects must be encoded before hashing")
+ if not isinstance(msg, six.binary_type):
+ raise TypeError(
+ "msg must be binary type. This is str in Python 2 and bytes "
+ "in Python 3"
+ )
self._ctx.update(msg)
def copy(self):
@@ -68,8 +71,11 @@ class HMAC(object):
return digest
def verify(self, signature):
- if isinstance(signature, six.text_type):
- raise TypeError("Unicode-objects must be encoded before verifying")
+ if not isinstance(signature, six.binary_type):
+ raise TypeError(
+ "signature must be binary type. This is str in Python 2 and "
+ "bytes in Python 3"
+ )
digest = self.finalize()
if not constant_time.bytes_eq(digest, signature):
raise InvalidSignature("Signature did not match digest.")