aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat/primitives/hmac.py
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2013-11-13 13:49:41 -0800
committerDavid Reid <dreid@dreid.org>2013-11-13 13:49:41 -0800
commit2cce618311c892aa5a1be2ef899e8ff7a08ae5ef (patch)
treee664e84cc5e3ee9f70a6f8ae9bb9ccf3d73fae26 /cryptography/hazmat/primitives/hmac.py
parentc2cddd2b1f0bd935ed53ee49446e268d9bf874e7 (diff)
downloadcryptography-2cce618311c892aa5a1be2ef899e8ff7a08ae5ef.tar.gz
cryptography-2cce618311c892aa5a1be2ef899e8ff7a08ae5ef.tar.bz2
cryptography-2cce618311c892aa5a1be2ef899e8ff7a08ae5ef.zip
Make HMAC methods raise AlreadyFinalized.
Diffstat (limited to 'cryptography/hazmat/primitives/hmac.py')
-rw-r--r--cryptography/hazmat/primitives/hmac.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py
index 1a67b332..cd0fd813 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()
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()
return HMAC(
self._key,
self.algorithm,
@@ -50,4 +55,9 @@ class HMAC(object):
)
def finalize(self):
- return self._ctx.finalize()
+ if self._ctx is None:
+ raise AlreadyFinalized()
+
+ digest = self._ctx.finalize()
+ self._ctx = None
+ return digest