aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-10-30 11:03:20 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-10-30 11:03:20 -0700
commit9172ea9d34cc3f2b162f56a143f1398fbba2dd20 (patch)
tree523c72842d6931a230691e59cc42b20c0bb7e5cb /cryptography/hazmat/primitives/hmac.py
parent90d08975edf01b2a5e4dd127d56799a185cd646b (diff)
downloadcryptography-9172ea9d34cc3f2b162f56a143f1398fbba2dd20.tar.gz
cryptography-9172ea9d34cc3f2b162f56a143f1398fbba2dd20.tar.bz2
cryptography-9172ea9d34cc3f2b162f56a143f1398fbba2dd20.zip
Remove duplicate code, now the verify method isn't special
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r--cryptography/hazmat/primitives/hmac.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index 22a31391..47a048ff 100644
--- a/cryptography/hazmat/primitives/hmac.py
+++ b/cryptography/hazmat/primitives/hmac.py
@@ -15,10 +15,10 @@ from __future__ import absolute_import, division, print_function
from cryptography import utils
from cryptography.exceptions import (
- AlreadyFinalized, InvalidSignature, UnsupportedAlgorithm, _Reasons
+ AlreadyFinalized, UnsupportedAlgorithm, _Reasons
)
from cryptography.hazmat.backends.interfaces import HMACBackend
-from cryptography.hazmat.primitives import constant_time, interfaces
+from cryptography.hazmat.primitives import interfaces
@utils.register_interface(interfaces.MACContext)
@@ -71,6 +71,8 @@ class HMAC(object):
def verify(self, signature):
if not isinstance(signature, bytes):
raise TypeError("signature must be bytes.")
- digest = self.finalize()
- if not constant_time.bytes_eq(digest, signature):
- raise InvalidSignature("Signature did not match digest.")
+ if self._ctx is None:
+ raise AlreadyFinalized("Context was already finalized.")
+
+ ctx, self._ctx = self._ctx, None
+ ctx.verify(signature)