diff options
Diffstat (limited to 'cryptography/hazmat')
-rw-r--r-- | cryptography/hazmat/primitives/ciphers/base.py | 5 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/hashes.py | 6 |
2 files changed, 7 insertions, 4 deletions
diff --git a/cryptography/hazmat/primitives/ciphers/base.py b/cryptography/hazmat/primitives/ciphers/base.py index 794d0191..0fe11996 100644 --- a/cryptography/hazmat/primitives/ciphers/base.py +++ b/cryptography/hazmat/primitives/ciphers/base.py @@ -13,6 +13,7 @@ from __future__ import absolute_import, division, print_function +from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.primitives import interfaces @@ -45,12 +46,12 @@ class _CipherContext(object): def update(self, data): if self._ctx is None: - raise ValueError("Context was already finalized") + raise AlreadyFinalized("Context was already finalized") return self._ctx.update(data) def finalize(self): if self._ctx is None: - raise ValueError("Context was already finalized") + raise AlreadyFinalized("Context was already finalized") data = self._ctx.finalize() self._ctx = None return data diff --git a/cryptography/hazmat/primitives/hashes.py b/cryptography/hazmat/primitives/hashes.py index b8de6c4b..86c9fe2e 100644 --- a/cryptography/hazmat/primitives/hashes.py +++ b/cryptography/hazmat/primitives/hashes.py @@ -39,19 +39,21 @@ class Hash(object): def update(self, data): if self._ctx is None: - raise AlreadyFinalized() + raise AlreadyFinalized("Context was already finalized") 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 AlreadyFinalized() + raise AlreadyFinalized("Context was already finalized") return Hash( self.algorithm, backend=self._backend, ctx=self._ctx.copy() ) def finalize(self): + if self._ctx is None: + raise AlreadyFinalized("Context was already finalized") digest = self._ctx.finalize() self._ctx = None return digest |