aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-12-27 08:22:07 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-12-27 08:22:07 -0800
commit4b31af7407ab6221712e8d83cd1bce53bd57aa95 (patch)
tree7b6774bc8559f51b47cb3510c244146ce20d00fb /cryptography/hazmat/primitives/hmac.py
parent3ac297e4c9b655b3222da1830e9677c9d03a3926 (diff)
parent37c88a0dea800b3028f95bf71a8cd6e344254d4e (diff)
downloadcryptography-4b31af7407ab6221712e8d83cd1bce53bd57aa95.tar.gz
cryptography-4b31af7407ab6221712e8d83cd1bce53bd57aa95.tar.bz2
cryptography-4b31af7407ab6221712e8d83cd1bce53bd57aa95.zip
Merge branch 'master' into fernet
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r--cryptography/hazmat/primitives/hmac.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index 618bccc5..76d658aa 100644
--- a/cryptography/hazmat/primitives/hmac.py
+++ b/cryptography/hazmat/primitives/hmac.py
@@ -16,8 +16,8 @@ from __future__ import absolute_import, division, print_function
import six
from cryptography import utils
-from cryptography.exceptions import AlreadyFinalized
-from cryptography.hazmat.primitives import interfaces
+from cryptography.exceptions import AlreadyFinalized, InvalidSignature
+from cryptography.hazmat.primitives import constant_time, interfaces
@utils.register_interface(interfaces.HashContext)
@@ -57,3 +57,10 @@ class HMAC(object):
digest = self._ctx.finalize()
self._ctx = None
return digest
+
+ def verify(self, signature):
+ if isinstance(signature, six.text_type):
+ raise TypeError("Unicode-objects must be encoded before verifying")
+ digest = self.finalize()
+ if not constant_time.bytes_eq(digest, signature):
+ raise InvalidSignature("Signature did not match digest.")