diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-21 18:34:00 -0600 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2015-02-25 07:49:52 -0600 |
commit | f83e25c81bb186ed8a96d4a569d5068546a24349 (patch) | |
tree | a34d97e993351ac1396e8d7481457cee21118171 /tests/hazmat/primitives/test_serialization.py | |
parent | 36394237388d19eacd3a80e79bf8c459cb234700 (diff) | |
download | cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.tar.gz cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.tar.bz2 cryptography-f83e25c81bb186ed8a96d4a569d5068546a24349.zip |
Support for traditional OpenSSL and PKCS8 RSA private key serialization
Diffstat (limited to 'tests/hazmat/primitives/test_serialization.py')
-rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index a17aac4b..2a5fb21d 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -18,8 +18,9 @@ from cryptography.hazmat.backends.interfaces import ( ) from cryptography.hazmat.primitives.asymmetric import dsa, ec, rsa from cryptography.hazmat.primitives.serialization import ( - load_der_private_key, load_der_public_key, load_pem_private_key, - load_pem_public_key, load_ssh_public_key + BestAvailable, Encoding, PKCS8, TraditionalOpenSSL, load_der_private_key, + load_der_public_key, load_pem_private_key, load_pem_public_key, + load_ssh_public_key ) @@ -1159,3 +1160,27 @@ class TestECDSASSHSerialization(object): ) with pytest.raises(ValueError): 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()) + + def test_encryption_with_zero_length_password(self): + with pytest.raises(ValueError): + BestAvailable(b"") |