aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-27 16:51:34 -0500
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-27 16:51:34 -0500
commit03c9ef407d9b58ac5cfc692ac4a92662dfda4421 (patch)
tree78b71d87ce2d21448dfeecd277f4e26a487636e3 /cryptography/hazmat/primitives/hmac.py
parent2dd6cc89f6822ede162ef402f270493b2263d829 (diff)
parent0ed17826ede036e0c24aa5c061dbb3132e8a330b (diff)
downloadcryptography-03c9ef407d9b58ac5cfc692ac4a92662dfda4421.tar.gz
cryptography-03c9ef407d9b58ac5cfc692ac4a92662dfda4421.tar.bz2
cryptography-03c9ef407d9b58ac5cfc692ac4a92662dfda4421.zip
Merge remote-tracking branch 'origin/master' into some-typedef-fixes
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.")