aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMichael Hart <mikeyman@hotmail.co.uk>2014-09-12 23:21:32 +0100
committerMichael Hart <mikeyman@hotmail.co.uk>2014-09-12 23:21:32 +0100
commitacda0445b1d22da120bbd46283e374887758c8b2 (patch)
treeb485d9cb85e41f913964f059ef1f3008a2bebd37 /tests
parented2a510d39d87540fc9c3a2239a0cdd34c7bc7de (diff)
downloadcryptography-acda0445b1d22da120bbd46283e374887758c8b2.tar.gz
cryptography-acda0445b1d22da120bbd46283e374887758c8b2.tar.bz2
cryptography-acda0445b1d22da120bbd46283e374887758c8b2.zip
Added PKCS8 encoded private keys to tests
Generated two files with the same private key as PEM_Serialization's ec_private_key.pem, one unencrypted and one encrypted with "123456". Also changed existing PEMSerialization unit tests to take parameters so that tests can be extended easily.
Diffstat (limited to 'tests')
-rw-r--r--tests/hazmat/primitives/test_serialization.py48
1 files changed, 30 insertions, 18 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
index 8542408b..7c912a92 100644
--- a/tests/hazmat/primitives/test_serialization.py
+++ b/tests/hazmat/primitives/test_serialization.py
@@ -49,29 +49,21 @@ class TestPEMSerialization(object):
if isinstance(key, interfaces.RSAPrivateKeyWithNumbers):
_check_rsa_private_numbers(key.private_numbers())
+ @pytest.mark.parametrize(
+ ("key_file", "password"),
+ [
+ ("ec_private_key.pem", None),
+ ("ec_private_key_encrypted.pem", b"123456"),
+ ]
+ )
@pytest.mark.elliptic
- def test_load_pem_ec_private_key_unencrypted(self, backend):
- _skip_curve_unsupported(backend, ec.SECP256R1())
- key = load_vectors_from_file(
- os.path.join(
- "asymmetric", "PEM_Serialization", "ec_private_key.pem"),
- lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), None, backend
- )
- )
-
- assert key
- assert isinstance(key, interfaces.EllipticCurvePrivateKey)
-
- @pytest.mark.elliptic
- def test_load_pem_ec_private_key_encrypted(self, backend):
+ 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", "PEM_Serialization",
- "ec_private_key_encrypted.pem"),
+ "asymmetric", "PEM_Serialization", key_file),
lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), b"123456", backend
+ pemfile.read().encode(), password, backend
)
)
@@ -335,6 +327,26 @@ class TestPKCS8Serialization(object):
if isinstance(key, interfaces.RSAPrivateKeyWithNumbers):
_check_rsa_private_numbers(key.private_numbers())
+ @pytest.mark.parametrize(
+ ("key_file", "password"),
+ [
+ ("ec_private_key.pem", None),
+ ("ec_private_key_encrypted.pem", b"123456"),
+ ]
+ )
+ @pytest.mark.elliptic
+ 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_pkcs8_private_key(
+ pemfile.read().encode(), password, backend
+ )
+ )
+ assert key
+ assert isinstance(key, interfaces.EllipticCurvePrivateKey)
+
def test_unused_password(self, backend):
key_file = os.path.join(
"asymmetric", "PKCS8", "unencpkcs8.pem")