From 152d6bec8c34c52d75373dd8d99a3d159baa9550 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 12 Nov 2013 16:41:13 -0800 Subject: raise an exception if you try to use a HashContext after finalize is called. --- tests/hazmat/primitives/test_hashes.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index 6cdb0a07..a5c440b8 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -19,6 +19,7 @@ import pytest import six +from cryptography import exceptions from cryptography.hazmat.bindings import _default_backend from cryptography.hazmat.primitives import hashes @@ -51,6 +52,16 @@ class TestHashContext(object): with pytest.raises(TypeError): hashes.Hash(hashes.SHA1) + def test_raises_after_finalize(self): + h = hashes.Hash(hashes.SHA1()) + h.finalize() + + with pytest.raises(exceptions.AlreadyFinalized): + h.update(b"foo") + + with pytest.raises(exceptions.AlreadyFinalized): + h.copy() + class TestSHA1(object): test_SHA1 = generate_base_hash_test( -- cgit v1.2.3 From 11e8cc7cf05967f203d5e7084756ccc28e43bdf7 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 13 Nov 2013 10:37:47 -0800 Subject: Import AlreadyFinalized instead of exceptions. --- tests/hazmat/primitives/test_hashes.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index a5c440b8..4c644603 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -19,7 +19,7 @@ import pytest import six -from cryptography import exceptions +from cryptography.exceptions import AlreadyFinalized from cryptography.hazmat.bindings import _default_backend from cryptography.hazmat.primitives import hashes @@ -56,10 +56,10 @@ class TestHashContext(object): h = hashes.Hash(hashes.SHA1()) h.finalize() - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): h.update(b"foo") - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): h.copy() -- cgit v1.2.3