aboutsummaryrefslogtreecommitdiffstats
path: root/tests/hazmat/primitives/test_serialization.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-22 07:56:05 -0600
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-12-22 07:56:05 -0600
commit85c11068b4eeb3d0bf1c42cfe4fb0659289566ab (patch)
tree433c5e9482a91639417cf3db7045cfcce6b039fa /tests/hazmat/primitives/test_serialization.py
parent217d417243956f703082451f5fd25d7586a69a4e (diff)
downloadcryptography-85c11068b4eeb3d0bf1c42cfe4fb0659289566ab.tar.gz
cryptography-85c11068b4eeb3d0bf1c42cfe4fb0659289566ab.tar.bz2
cryptography-85c11068b4eeb3d0bf1c42cfe4fb0659289566ab.zip
consolidate dsa serialization loading tests and improve verifier
Diffstat (limited to 'tests/hazmat/primitives/test_serialization.py')
-rw-r--r--tests/hazmat/primitives/test_serialization.py44
1 files changed, 19 insertions, 25 deletions
diff --git a/tests/hazmat/primitives/test_serialization.py b/tests/hazmat/primitives/test_serialization.py
index 6169dd83..8a7e7f67 100644
--- a/tests/hazmat/primitives/test_serialization.py
+++ b/tests/hazmat/primitives/test_serialization.py
@@ -25,7 +25,10 @@ from cryptography.hazmat.primitives.serialization import (
from .test_ec import _skip_curve_unsupported
-from .utils import _check_rsa_private_numbers, load_vectors_from_file
+from .utils import (
+ _check_dsa_private_numbers, _check_rsa_private_numbers,
+ load_vectors_from_file
+)
from ...utils import raises_unsupported_algorithm
@@ -63,16 +66,27 @@ class TestPEMSerialization(object):
if isinstance(key, interfaces.RSAPrivateKeyWithNumbers):
_check_rsa_private_numbers(key.private_numbers())
- def test_load_dsa_private_key(self, backend):
+ @pytest.mark.parametrize(
+ ("key_path", "password"),
+ [
+ (["Traditional_OpenSSL_Serialization", "dsa.1024.pem"], None),
+ (["Traditional_OpenSSL_Serialization", "dsa.2048.pem"], None),
+ (["Traditional_OpenSSL_Serialization", "dsa.3072.pem"], None),
+ (["PKCS8", "unenc-dsa-pkcs8.pem"], None),
+ (["PEM_Serialization", "dsa_private_key.pem"], b"123456"),
+ ]
+ )
+ def test_load_dsa_private_key(self, key_path, password, backend):
key = load_vectors_from_file(
- os.path.join(
- "asymmetric", "PEM_Serialization", "dsa_private_key.pem"),
+ os.path.join("asymmetric", *key_path),
lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), b"123456", backend
+ pemfile.read().encode(), password, backend
)
)
assert key
assert isinstance(key, interfaces.DSAPrivateKey)
+ if isinstance(key, interfaces.DSAPrivateKeyWithNumbers):
+ _check_dsa_private_numbers(key.private_numbers())
@pytest.mark.parametrize(
("key_file", "password"),
@@ -179,26 +193,6 @@ class TestTraditionalOpenSSLSerialization(object):
if isinstance(key, interfaces.RSAPrivateKeyWithNumbers):
_check_rsa_private_numbers(key.private_numbers())
- @pytest.mark.parametrize(
- ("key_file", "password"),
- [
- ("dsa.1024.pem", None),
- ("dsa.2048.pem", None),
- ("dsa.3072.pem", None),
- ]
- )
- def test_load_pem_dsa_private_key(self, key_file, password, backend):
- key = load_vectors_from_file(
- os.path.join(
- "asymmetric", "Traditional_OpenSSL_Serialization", key_file),
- lambda pemfile: load_pem_private_key(
- pemfile.read().encode(), password, backend
- )
- )
-
- assert key
- assert isinstance(key, interfaces.DSAPrivateKey)
-
def test_key1_pem_encrypted_values(self, backend):
pkey = load_vectors_from_file(
os.path.join(