aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_serialization.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-22 10:00:49 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-23 15:22:22 -0600
commit35d2931e32bca6d4ed20a15d108fedfab4ed6afa (patch)
tree985234a5c87475d2ebaff1677ad528e175ce64c4 /tests/hazmat/primitives/test_serialization.py
parent5bdf1a85323767c1654a702e884aa3f5d8720806 (diff)
downloadcryptography-35d2931e32bca6d4ed20a15d108fedfab4ed6afa.tar.gz
cryptography-35d2931e32bca6d4ed20a15d108fedfab4ed6afa.tar.bz2
cryptography-35d2931e32bca6d4ed20a15d108fedfab4ed6afa.zip
final cleanup for PEM serialization
Diffstat (limited to 'tests/hazmat/primitives/test_serialization.py')
-rw-r--r--tests/hazmat/primitives/test_serialization.py71
1 files changed, 11 insertions, 60 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
index 0eca8a67..b2067ca5 100644
--- a/tests/hazmat/primitives/test_serialization.py
+++ b/tests/hazmat/primitives/test_serialization.py
@@ -114,6 +114,8 @@ class TestPEMSerialization(object):
assert key
assert isinstance(key, interfaces.EllipticCurvePrivateKey)
+ assert key.curve.name == "secp256r1"
+ assert key.curve.key_size == 256
@pytest.mark.parametrize(
("key_file"),
@@ -171,12 +173,7 @@ class TestPEMSerialization(object):
assert key.curve.name == "secp256r1"
assert key.curve.key_size == 256
-
-@pytest.mark.requires_backend_interface(
- interface=PEMSerializationBackend
-)
-class TestTraditionalOpenSSLSerialization(object):
- def test_key1_pem_encrypted_values(self, backend):
+ def test_rsa_traditional_encrypted_values(self, backend):
pkey = load_vectors_from_file(
os.path.join(
"asymmetric", "Traditional_OpenSSL_Serialization", "key1.pem"),
@@ -292,7 +289,7 @@ class TestTraditionalOpenSSLSerialization(object):
key_data, b"this password will not be used", backend
)
- def test_corrupt_format(self, backend):
+ def test_corrupt_traditional_format(self, backend):
# privkey.pem with a bunch of data missing.
key_data = textwrap.dedent("""\
-----BEGIN RSA PRIVATE KEY-----
@@ -315,7 +312,7 @@ class TestTraditionalOpenSSLSerialization(object):
key_data, b"this password will not be used", backend
)
- def test_encrypted_corrupt_format(self, backend):
+ def test_traditional_encrypted_corrupt_format(self, backend):
# privkey.pem with a single bit flipped
key_data = textwrap.dedent("""\
-----BEGIN RSA PRIVATE KEY-----
@@ -367,46 +364,7 @@ class TestTraditionalOpenSSLSerialization(object):
key_data, password, backend
)
-
-@pytest.mark.requires_backend_interface(interface=PEMSerializationBackend)
-class TestPKCS8Serialization(object):
-
- @pytest.mark.parametrize(
- ("key_file", "password"),
- [
- ("ec_private_key.pem", None),
- ("ec_private_key_encrypted.pem", b"123456"),
- ]
- )
- @pytest.mark.requires_backend_interface(interface=EllipticCurveBackend)
- def test_load_pem_ec_private_key(self, key_file, password, backend):
- _skip_curve_unsupported(backend, ec.SECP256R1())
- key = load_vectors_from_file(
- os.path.join(
- "asymmetric", "PKCS8", key_file),
- lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), password, backend
- )
- )
- assert key
- assert isinstance(key, interfaces.EllipticCurvePrivateKey)
- assert key.curve.name == "secp256r1"
- assert key.curve.key_size == 256
-
- def test_wrong_format(self, backend):
- key_data = b"---- NOT A KEY ----\n"
-
- with pytest.raises(ValueError):
- load_pem_private_key(
- key_data, None, backend
- )
-
- with pytest.raises(ValueError):
- load_pem_private_key(
- key_data, b"this password will not be used", backend
- )
-
- def test_corrupt_format(self, backend):
+ def test_corrupt_pkcs8_format(self, backend):
# unenc-rsa-pkcs8.pem with a bunch of data missing.
key_data = textwrap.dedent("""\
-----BEGIN PRIVATE KEY-----
@@ -436,7 +394,7 @@ class TestPKCS8Serialization(object):
key_data, b"this password will not be used", backend
)
- def test_encrypted_corrupt_format(self, backend):
+ def test_pks8_encrypted_corrupt_format(self, backend):
# enc-rsa-pkcs8.pem with some bits flipped.
key_data = textwrap.dedent("""\
-----BEGIN ENCRYPTED PRIVATE KEY-----
@@ -470,7 +428,7 @@ class TestPKCS8Serialization(object):
key_data, password, backend
)
- def test_key1_pem_encrypted_values(self, backend):
+ def test_rsa_pkcs8_encrypted_values(self, backend):
pkey = load_vectors_from_file(
os.path.join(
"asymmetric", "PKCS8", "enc-rsa-pkcs8.pem"),
@@ -530,18 +488,11 @@ class TestPKCS8Serialization(object):
"97ccfe7f", 16
)
- @pytest.mark.parametrize(
- ("key_file", "password"),
- [
- ("unenc-dsa-pkcs8.pem", None),
- ]
- )
- def test_load_pem_dsa_private_key(self, key_file, password, backend):
+ def test_load_pem_dsa_private_key(self, backend):
key = load_vectors_from_file(
- os.path.join(
- "asymmetric", "PKCS8", key_file),
+ os.path.join("asymmetric", "PKCS8", "unenc-dsa-pkcs8.pem"),
lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), password, backend
+ pemfile.read().encode(), None, backend
)
)
assert key