From 7a489dbd116edd4ca5a6104b74748f3a4f712d15 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sat, 22 Mar 2014 15:09:34 -0700 Subject: Fixed #809 -- switch back to always using UnsupportedAlgorithm --- tests/hazmat/primitives/test_rsa.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'tests/hazmat/primitives/test_rsa.py') diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index eb7e1e60..2d3ce092 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -21,9 +21,9 @@ import os import pytest -from cryptography import exceptions, utils +from cryptography import utils from cryptography.exceptions import ( - UnsupportedAlgorithm, UnsupportedInterface + AlreadyFinalized, InvalidSignature, UnsupportedAlgorithm ) from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import padding, rsa @@ -398,7 +398,7 @@ class TestRSA(object): def test_rsa_generate_invalid_backend(): pretend_backend = object() - with pytest.raises(UnsupportedInterface): + with pytest.raises(UnsupportedAlgorithm): rsa.RSAPrivateKey.generate(65537, 2048, pretend_backend) @@ -594,9 +594,9 @@ class TestRSASignature(object): signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1(), backend) signer.update(b"sign me") signer.finalize() - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): signer.finalize() - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): signer.update(b"more data") def test_unsupported_padding(self, backend): @@ -605,7 +605,7 @@ class TestRSASignature(object): key_size=512, backend=backend ) - with pytest.raises(exceptions.UnsupportedPadding): + with pytest.raises(UnsupportedAlgorithm): private_key.signer(DummyPadding(), hashes.SHA1(), backend) def test_padding_incorrect_type(self, backend): @@ -621,7 +621,7 @@ class TestRSASignature(object): pretend_backend = object() private_key = rsa.RSAPrivateKey.generate(65537, 2048, backend) - with pytest.raises(UnsupportedInterface): + with pytest.raises(UnsupportedAlgorithm): private_key.signer( padding.PKCS1v15(), hashes.SHA256, pretend_backend) @@ -678,7 +678,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"incorrect data") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() def test_invalid_pkcs1v15_signature_wrong_key(self, backend): @@ -703,7 +703,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() @pytest.mark.parametrize( @@ -759,7 +759,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"incorrect data") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() def test_invalid_pss_signature_wrong_key(self, backend): @@ -789,7 +789,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() def test_invalid_pss_signature_data_too_large_for_modulus(self, backend): @@ -819,7 +819,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() def test_use_after_finalize(self, backend): @@ -841,9 +841,9 @@ class TestRSAVerification(object): ) verifier.update(b"sign me") verifier.verify() - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): verifier.verify() - with pytest.raises(exceptions.AlreadyFinalized): + with pytest.raises(AlreadyFinalized): verifier.update(b"more data") def test_unsupported_padding(self, backend): @@ -853,7 +853,7 @@ class TestRSAVerification(object): backend=backend ) public_key = private_key.public_key() - with pytest.raises(exceptions.UnsupportedPadding): + with pytest.raises(UnsupportedAlgorithm): public_key.verifier(b"sig", DummyPadding(), hashes.SHA1(), backend) def test_padding_incorrect_type(self, backend): @@ -871,7 +871,7 @@ class TestRSAVerification(object): private_key = rsa.RSAPrivateKey.generate(65537, 2048, backend) public_key = private_key.public_key() - with pytest.raises(UnsupportedInterface): + with pytest.raises(UnsupportedAlgorithm): public_key.verifier( b"foo", padding.PKCS1v15(), hashes.SHA256(), pretend_backend) @@ -939,7 +939,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(exceptions.InvalidSignature): + with pytest.raises(InvalidSignature): verifier.verify() -- cgit v1.2.3 From 4c1401a3745af97fcd398ff5b7f0dcb94f5292a0 Mon Sep 17 00:00:00 2001 From: Alex Stapleton Date: Wed, 26 Mar 2014 20:26:49 +0000 Subject: Update tests and raise sites --- tests/hazmat/primitives/test_rsa.py | 39 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'tests/hazmat/primitives/test_rsa.py') diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 2d3ce092..5d94e790 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -21,16 +21,15 @@ import os import pytest -from cryptography import utils -from cryptography.exceptions import ( - AlreadyFinalized, InvalidSignature, UnsupportedAlgorithm -) +from cryptography import exceptions, utils +from cryptography.exceptions import UnsupportedAlgorithm, _Reasons from cryptography.hazmat.primitives import hashes, interfaces from cryptography.hazmat.primitives.asymmetric import padding, rsa from .utils import generate_rsa_verification_test from ...utils import ( - load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file + load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file, + raises_unsupported_algorithm ) @@ -398,7 +397,7 @@ class TestRSA(object): def test_rsa_generate_invalid_backend(): pretend_backend = object() - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.BACKEND_MISSING_INTERFACE): rsa.RSAPrivateKey.generate(65537, 2048, pretend_backend) @@ -594,9 +593,9 @@ class TestRSASignature(object): signer = private_key.signer(padding.PKCS1v15(), hashes.SHA1(), backend) signer.update(b"sign me") signer.finalize() - with pytest.raises(AlreadyFinalized): + with pytest.raises(exceptions.AlreadyFinalized): signer.finalize() - with pytest.raises(AlreadyFinalized): + with pytest.raises(exceptions.AlreadyFinalized): signer.update(b"more data") def test_unsupported_padding(self, backend): @@ -605,7 +604,7 @@ class TestRSASignature(object): key_size=512, backend=backend ) - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING): private_key.signer(DummyPadding(), hashes.SHA1(), backend) def test_padding_incorrect_type(self, backend): @@ -621,7 +620,7 @@ class TestRSASignature(object): pretend_backend = object() private_key = rsa.RSAPrivateKey.generate(65537, 2048, backend) - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.BACKEND_MISSING_INTERFACE): private_key.signer( padding.PKCS1v15(), hashes.SHA256, pretend_backend) @@ -678,7 +677,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"incorrect data") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() def test_invalid_pkcs1v15_signature_wrong_key(self, backend): @@ -703,7 +702,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() @pytest.mark.parametrize( @@ -759,7 +758,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"incorrect data") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() def test_invalid_pss_signature_wrong_key(self, backend): @@ -789,7 +788,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() def test_invalid_pss_signature_data_too_large_for_modulus(self, backend): @@ -819,7 +818,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() def test_use_after_finalize(self, backend): @@ -841,9 +840,9 @@ class TestRSAVerification(object): ) verifier.update(b"sign me") verifier.verify() - with pytest.raises(AlreadyFinalized): + with pytest.raises(exceptions.AlreadyFinalized): verifier.verify() - with pytest.raises(AlreadyFinalized): + with pytest.raises(exceptions.AlreadyFinalized): verifier.update(b"more data") def test_unsupported_padding(self, backend): @@ -853,7 +852,7 @@ class TestRSAVerification(object): backend=backend ) public_key = private_key.public_key() - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.UNSUPPORTED_PADDING): public_key.verifier(b"sig", DummyPadding(), hashes.SHA1(), backend) def test_padding_incorrect_type(self, backend): @@ -871,7 +870,7 @@ class TestRSAVerification(object): private_key = rsa.RSAPrivateKey.generate(65537, 2048, backend) public_key = private_key.public_key() - with pytest.raises(UnsupportedAlgorithm): + with raises_unsupported_algorithm(_Reasons.BACKEND_MISSING_INTERFACE): public_key.verifier( b"foo", padding.PKCS1v15(), hashes.SHA256(), pretend_backend) @@ -939,7 +938,7 @@ class TestRSAVerification(object): backend ) verifier.update(b"sign me") - with pytest.raises(InvalidSignature): + with pytest.raises(exceptions.InvalidSignature): verifier.verify() -- cgit v1.2.3