diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-09-12 19:47:39 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2014-09-12 19:47:39 -0500 |
commit | 5f47335ce58b7ea31a39ece81e3ff8e523f80168 (patch) | |
tree | b485d9cb85e41f913964f059ef1f3008a2bebd37 /tests/hazmat | |
parent | b8599c085d3e295f460f0117f7df9288a4841d7f (diff) | |
parent | acda0445b1d22da120bbd46283e374887758c8b2 (diff) | |
download | cryptography-5f47335ce58b7ea31a39ece81e3ff8e523f80168.tar.gz cryptography-5f47335ce58b7ea31a39ece81e3ff8e523f80168.tar.bz2 cryptography-5f47335ce58b7ea31a39ece81e3ff8e523f80168.zip |
Merge pull request #1328 from michael-hart/master
Implemented support for loading EC private keys
Diffstat (limited to 'tests/hazmat')
-rw-r--r-- | tests/hazmat/primitives/test_serialization.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py index 9333a6bd..7c912a92 100644 --- a/tests/hazmat/primitives/test_serialization.py +++ b/tests/hazmat/primitives/test_serialization.py @@ -21,11 +21,14 @@ import pytest from cryptography.exceptions import _Reasons from cryptography.hazmat.primitives import interfaces +from cryptography.hazmat.primitives.asymmetric import ec from cryptography.hazmat.primitives.serialization import ( load_pem_pkcs8_private_key, load_pem_private_key, load_pem_traditional_openssl_private_key ) + +from .test_ec import _skip_curve_unsupported from .utils import _check_rsa_private_numbers, load_vectors_from_file from ...utils import raises_unsupported_algorithm @@ -46,6 +49,27 @@ 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(self, key_file, password, backend): + _skip_curve_unsupported(backend, ec.SECP256R1()) + key = load_vectors_from_file( + os.path.join( + "asymmetric", "PEM_Serialization", key_file), + lambda pemfile: load_pem_private_key( + pemfile.read().encode(), password, backend + ) + ) + + assert key + assert isinstance(key, interfaces.EllipticCurvePrivateKey) + @pytest.mark.traditional_openssl_serialization class TestTraditionalOpenSSLSerialization(object): @@ -303,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") |