aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography/hazmat
diff options
context:
space:
mode:
Diffstat (limited to 'cryptography/hazmat')
-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