diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-01-01 08:11:13 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-01-01 08:11:13 -0800 |
commit | 2a160d6a159817dd9d08a84e77d102e328f9af4f (patch) | |
tree | 461b7c607367f243bb46996ec16ad7424e48d440 /cryptography/hazmat/primitives/hmac.py | |
parent | 62aefffb1396190930074bf04c91459d1536bd0e (diff) | |
parent | 522487e5a7dd3004747da85c9f6c53fc5dc4de06 (diff) | |
download | cryptography-2a160d6a159817dd9d08a84e77d102e328f9af4f.tar.gz cryptography-2a160d6a159817dd9d08a84e77d102e328f9af4f.tar.bz2 cryptography-2a160d6a159817dd9d08a84e77d102e328f9af4f.zip |
Merge branch 'master' into validate-iv
Conflicts:
tests/hazmat/backends/test_openssl.py
tests/hazmat/primitives/test_block.py
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r-- | cryptography/hazmat/primitives/hmac.py | 11 |
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.") |