diff options
Diffstat (limited to 'cryptography/hazmat/primitives/hashes.py')
-rw-r--r-- | cryptography/hazmat/primitives/hashes.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/cryptography/hazmat/primitives/hashes.py b/cryptography/hazmat/primitives/hashes.py index 6ae622cd..f85d36a0 100644 --- a/cryptography/hazmat/primitives/hashes.py +++ b/cryptography/hazmat/primitives/hashes.py @@ -15,6 +15,7 @@ from __future__ import absolute_import, division, print_function import six +from cryptography import exceptions from cryptography.hazmat.primitives import interfaces @@ -37,17 +38,23 @@ class Hash(object): self._ctx = ctx def update(self, data): + if self._ctx is None: + raise exceptions.AlreadyFinalized() if isinstance(data, six.text_type): raise TypeError("Unicode-objects must be encoded before hashing") self._ctx.update(data) def copy(self): + if self._ctx is None: + raise exceptions.AlreadyFinalized() return Hash( self.algorithm, backend=self._backend, ctx=self._ctx.copy() ) def finalize(self): - return self._ctx.finalize() + digest = self._ctx.finalize() + self._ctx = None + return digest @interfaces.register(interfaces.HashAlgorithm) |