diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-23 20:45:21 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-25 07:50:25 -0600 |
commit | 199dc276cd1b45a799b511090b37237df49d68a3 (patch) | |
tree | 448ed0a7f78542c967e4515c3f3f817104cc40a0 /tests | |
parent | f83e25c81bb186ed8a96d4a569d5068546a24349 (diff) | |
download | cryptography-199dc276cd1b45a799b511090b37237df49d68a3.tar.gz cryptography-199dc276cd1b45a799b511090b37237df49d68a3.tar.bz2 cryptography-199dc276cd1b45a799b511090b37237df49d68a3.zip |
address review comments
Diffstat (limited to 'tests')
-rw-r--r-- | tests/hazmat/backends/test_openssl.py | 12 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_rsa.py | 51 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 23 |
3 files changed, 43 insertions, 43 deletions
diff --git a/tests/hazmat/backends/test_openssl.py b/tests/hazmat/backends/test_openssl.py index 35b7c5c3..b5de702d 100644 --- a/tests/hazmat/backends/test_openssl.py +++ b/tests/hazmat/backends/test_openssl.py @@ -503,18 +503,16 @@ class TestRSAPEMSerialization(object): key = RSA_KEY_2048.private_key(backend) with pytest.raises(ValueError): key.dump( - serialization.PKCS8( - serialization.Encoding.PEM - ), - serialization.BestAvailable(password) + serialization.Encoding.PEM, + serialization.Format.PKCS8, + serialization.BestAvailableEncryption(password) ) def test_unsupported_key_encoding(self): key = RSA_KEY_2048.private_key(backend) with pytest.raises(ValueError): key.dump( - serialization.PKCS8( - serialization.Encoding.DER - ), + serialization.Encoding.DER, + serialization.Format.PKCS8, serialization.NoEncryption() ) diff --git a/tests/hazmat/primitives/test_rsa.py b/tests/hazmat/primitives/test_rsa.py index 72bc08ad..a0df2f26 100644 --- a/tests/hazmat/primitives/test_rsa.py +++ b/tests/hazmat/primitives/test_rsa.py @@ -1750,9 +1750,12 @@ class TestRSAPrimeFactorRecovery(object): @pytest.mark.requires_backend_interface(interface=PEMSerializationBackend) class TestRSAPEMWriter(object): @pytest.mark.parametrize( - ("serializer", "password"), + ("fmt", "password"), itertools.product( - [serialization.TraditionalOpenSSL, serialization.PKCS8], + [ + serialization.Format.TraditionalOpenSSL, + serialization.Format.PKCS8 + ], [ b"s", b"longerpassword", @@ -1761,12 +1764,13 @@ class TestRSAPEMWriter(object): ] ) ) - def test_dump_encrypted_pem(self, backend, serializer, password): + def test_dump_encrypted_pem(self, backend, fmt, password): key = RSA_KEY_2048.private_key(backend) _skip_if_no_serialization(key, backend) serialized = key.dump( - serializer(serialization.Encoding.PEM), - serialization.BestAvailable(password) + serialization.Encoding.PEM, + fmt, + serialization.BestAvailableEncryption(password) ) loaded_key = serialization.load_pem_private_key( serialized, password, backend @@ -1776,14 +1780,15 @@ class TestRSAPEMWriter(object): assert loaded_priv_num == priv_num @pytest.mark.parametrize( - "serializer", - (serialization.TraditionalOpenSSL, serialization.PKCS8), + "fmt", + (serialization.Format.TraditionalOpenSSL, serialization.Format.PKCS8), ) - def test_dump_unencrypted_pem(self, backend, serializer): + def test_dump_unencrypted_pem(self, backend, fmt): key = RSA_KEY_2048.private_key(backend) _skip_if_no_serialization(key, backend) serialized = key.dump( - serializer(serialization.Encoding.PEM), + serialization.Encoding.PEM, + fmt, serialization.NoEncryption() ) loaded_key = serialization.load_pem_private_key( @@ -1793,20 +1798,33 @@ class TestRSAPEMWriter(object): priv_num = key.private_numbers() assert loaded_priv_num == priv_num - def test_dump_invalid_serializer(self, backend): + def test_dump_invalid_encoding(self, backend): key = RSA_KEY_2048.private_key(backend) _skip_if_no_serialization(key, backend) with pytest.raises(TypeError): - key.dump("notaserializer", serialization.NoEncryption()) + key.dump( + "notencoding", + serialization.Format.PKCS8, + serialization.NoEncryption() + ) + + def test_dump_invalid_format(self, backend): + key = RSA_KEY_2048.private_key(backend) + _skip_if_no_serialization(key, backend) + with pytest.raises(TypeError): + key.dump( + serialization.Encoding.PEM, + "invalidformat", + serialization.NoEncryption() + ) def test_dump_invalid_encryption_algorithm(self, backend): key = RSA_KEY_2048.private_key(backend) _skip_if_no_serialization(key, backend) with pytest.raises(TypeError): key.dump( - serialization.TraditionalOpenSSL( - serialization.Encoding.PEM - ), + serialization.Encoding.PEM, + serialization.Format.TraditionalOpenSSL, "notanencalg" ) @@ -1815,8 +1833,7 @@ class TestRSAPEMWriter(object): _skip_if_no_serialization(key, backend) with pytest.raises(ValueError): key.dump( - serialization.TraditionalOpenSSL( - serialization.Encoding.PEM - ), + serialization.Encoding.PEM, + serialization.Format.TraditionalOpenSSL, DummyKeyEncryption() ) diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 2a5fb21d..fc8f8664 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -18,9 +18,8 @@ from cryptography.hazmat.backends.interfaces import ( ) from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa from cryptography.hazmat.primitives.serialization import ( - BestAvailable, Encoding, PKCS8, TraditionalOpenSSL, load_der_private_key, - load_der_public_key, load_pem_private_key, load_pem_public_key, - load_ssh_public_key + BestAvailableEncryption, load_der_private_key, load_der_public_key, + load_pem_private_key, load_pem_public_key, load_ssh_public_key ) @@ -1162,25 +1161,11 @@ class TestECDSASSHSerialization(object): load_ssh_public_key(ssh_key, backend) -@pytest.mark.parametrize( - "serializer", - [PKCS8, TraditionalOpenSSL] -) -class TestSerializers(object): - def test_invalid_encoding(self, serializer): - with pytest.raises(TypeError): - serializer("thing") - - def test_valid_params(self, serializer): - fmt = serializer(Encoding.PEM) - assert isinstance(fmt, (PKCS8, TraditionalOpenSSL)) - - class TestKeySerializationEncryptionTypes(object): def test_non_bytes_password(self): with pytest.raises(ValueError): - BestAvailable(object()) + BestAvailableEncryption(object()) def test_encryption_with_zero_length_password(self): with pytest.raises(ValueError): - BestAvailable(b"") + BestAvailableEncryption(b"") |