diff options
Diffstat (limited to 'tests/hazmat')
| -rw-r--r-- | tests/hazmat/primitives/test_hashes.py | 27 | ||||
| -rw-r--r-- | tests/hazmat/primitives/test_hmac.py | 27 | 
2 files changed, 52 insertions, 2 deletions
| diff --git a/tests/hazmat/primitives/test_hashes.py b/tests/hazmat/primitives/test_hashes.py index 45faaab2..69d0773a 100644 --- a/tests/hazmat/primitives/test_hashes.py +++ b/tests/hazmat/primitives/test_hashes.py @@ -20,7 +20,9 @@ import pytest  import six  from cryptography import utils -from cryptography.exceptions import AlreadyFinalized, UnsupportedAlgorithm +from cryptography.exceptions import ( +    AlreadyFinalized, UnsupportedAlgorithm, InvalidSignature +)  from cryptography.hazmat.primitives import hashes, interfaces  from .utils import generate_base_hash_test @@ -64,6 +66,29 @@ class TestHashContext(object):          with pytest.raises(AlreadyFinalized):              h.finalize() +    def test_verify(self, backend): +        h = hashes.Hash(hashes.SHA1(), backend=backend) +        digest = h.finalize() + +        h = hashes.Hash(hashes.SHA1(), backend=backend) +        h.verify(digest) + +        with pytest.raises(AlreadyFinalized): +            h.verify(b'') + +    def test_invalid_verify(self, backend): +        h = hashes.Hash(hashes.SHA1(), backend=backend) +        with pytest.raises(InvalidSignature): +            h.verify(b'') + +        with pytest.raises(AlreadyFinalized): +            h.verify(b'') + +    def test_verify_reject_unicode(self, backend): +        h = hashes.Hash(hashes.SHA1(), backend=backend) +        with pytest.raises(TypeError): +            h.verify(six.u('')) +      def test_unsupported_hash(self, backend):          with pytest.raises(UnsupportedAlgorithm):              hashes.Hash(UnsupportedDummyHash(), backend) diff --git a/tests/hazmat/primitives/test_hmac.py b/tests/hazmat/primitives/test_hmac.py index 6d8cc27b..7acb78b7 100644 --- a/tests/hazmat/primitives/test_hmac.py +++ b/tests/hazmat/primitives/test_hmac.py @@ -20,7 +20,9 @@ import pytest  import six  from cryptography import utils -from cryptography.exceptions import AlreadyFinalized, UnsupportedAlgorithm +from cryptography.exceptions import ( +    AlreadyFinalized, UnsupportedAlgorithm, InvalidSignature +)  from cryptography.hazmat.primitives import hashes, hmac, interfaces  from .utils import generate_base_hmac_test @@ -71,6 +73,29 @@ class TestHMAC(object):          with pytest.raises(AlreadyFinalized):              h.finalize() +    def test_verify(self, backend): +        h = hmac.HMAC(b'', hashes.SHA1(), backend=backend) +        digest = h.finalize() + +        h = hmac.HMAC(b'', hashes.SHA1(), backend=backend) +        h.verify(digest) + +        with pytest.raises(AlreadyFinalized): +            h.verify(b'') + +    def test_invalid_verify(self, backend): +        h = hmac.HMAC(b'', hashes.SHA1(), backend=backend) +        with pytest.raises(InvalidSignature): +            h.verify(b'') + +        with pytest.raises(AlreadyFinalized): +            h.verify(b'') + +    def test_verify_reject_unicode(self, backend): +        h = hmac.HMAC(b'', hashes.SHA1(), backend=backend) +        with pytest.raises(TypeError): +            h.verify(six.u('')) +      def test_unsupported_hash(self, backend):          with pytest.raises(UnsupportedAlgorithm):              hmac.HMAC(b"key", UnsupportedDummyHash(), backend) | 
