diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-10-31 10:15:09 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-10-31 10:15:09 -0500 |
commit | 87f8a23d8e182164d820c99d6de66c8771f30ae5 (patch) | |
tree | 46f36af76e4ea9d5a7ae3256027a93fd492d6825 /cryptography/hazmat/primitives/cmac.py | |
parent | 083091eaef3f84d23eee6c7390d074d05ef78d96 (diff) | |
parent | a201cde67233018545120cd0245a0ffb9905e89f (diff) | |
download | cryptography-87f8a23d8e182164d820c99d6de66c8771f30ae5.tar.gz cryptography-87f8a23d8e182164d820c99d6de66c8771f30ae5.tar.bz2 cryptography-87f8a23d8e182164d820c99d6de66c8771f30ae5.zip |
Merge pull request #1455 from alex/verify-all-the-things
Make sure the backend implementatinos of various interfaces have verify() methods.
Diffstat (limited to 'cryptography/hazmat/primitives/cmac.py')
-rw-r--r-- | cryptography/hazmat/primitives/cmac.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py index 7ae5c118..6f722031 100644 --- a/cryptography/hazmat/primitives/cmac.py +++ b/cryptography/hazmat/primitives/cmac.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 CMACBackend -from cryptography.hazmat.primitives import constant_time, interfaces +from cryptography.hazmat.primitives import interfaces @utils.register_interface(interfaces.MACContext) @@ -59,9 +59,11 @@ class CMAC(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) def copy(self): if self._ctx is None: |