diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-13 16:38:45 -0800 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-11-13 16:38:45 -0800 |
commit | 5ef7624d4a61c14b2247903149f4f2675db5b722 (patch) | |
tree | af6733cbb02f0a17280b6ab115a1c437ae9c8aee /cryptography/hazmat/primitives/hmac.py | |
parent | a502c5009f1fd4a0def66a17f890b6f9c5602bd5 (diff) | |
parent | ee66145fc79f1ef2840267718f54fd89463c67f5 (diff) | |
download | cryptography-5ef7624d4a61c14b2247903149f4f2675db5b722.tar.gz cryptography-5ef7624d4a61c14b2247903149f4f2675db5b722.tar.bz2 cryptography-5ef7624d4a61c14b2247903149f4f2675db5b722.zip |
Merge pull request #260 from dreid/hmac-already-finalized
Make HMAC methods raise AlreadyFinalized.
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r-- | cryptography/hazmat/primitives/hmac.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py index 1a67b332..1bbe39c7 100644 --- a/cryptography/hazmat/primitives/hmac.py +++ b/cryptography/hazmat/primitives/hmac.py @@ -15,6 +15,7 @@ from __future__ import absolute_import, division, print_function import six +from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.primitives import interfaces @@ -37,11 +38,15 @@ class HMAC(object): self._ctx = ctx def update(self, msg): + if self._ctx is None: + raise AlreadyFinalized("Context was already finalized") if isinstance(msg, six.text_type): raise TypeError("Unicode-objects must be encoded before hashing") self._ctx.update(msg) def copy(self): + if self._ctx is None: + raise AlreadyFinalized("Context was already finalized") return HMAC( self._key, self.algorithm, @@ -50,4 +55,8 @@ class HMAC(object): ) def finalize(self): - return self._ctx.finalize() + if self._ctx is None: + raise AlreadyFinalized("Context was already finalized") + digest = self._ctx.finalize() + self._ctx = None + return digest |