aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorDavid Reid <dreid@dreid.org>2014-02-19 09:33:49 -0800
committerDavid Reid <dreid@dreid.org>2014-02-19 09:33:49 -0800
commitd750e9b3ded1bdae43a3bbd99b1f463c75317a2b (patch)
treebc47a5368f31e37f89cb14d8689d9d38892b7bcf /tests/utils.py
parentf8cf48bb4a751451ebb7571e91e1eda3b7345e88 (diff)
parent7d9c306cd6bd1a3250d7b85e812b9cb90aaa3fd3 (diff)
downloadcryptography-d750e9b3ded1bdae43a3bbd99b1f463c75317a2b.tar.gz
cryptography-d750e9b3ded1bdae43a3bbd99b1f463c75317a2b.tar.bz2
cryptography-d750e9b3ded1bdae43a3bbd99b1f463c75317a2b.zip
Merge pull request #636 from reaperhulk/rsa-signature-loader
Expand PKCS1 loader to load PKCS1 v1.5 and PSS signature examples
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py46
1 files changed, 44 insertions, 2 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 3c150a2e..6679e907 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -177,16 +177,55 @@ def load_hash_vectors(vector_data):
def load_pkcs1_vectors(vector_data):
"""
Loads data out of RSA PKCS #1 vector files.
-
- Currently only returns the key pairs.
"""
private_key_vector = None
public_key_vector = None
attr = None
key = None
+ example_vector = None
+ examples = []
vectors = []
for line in vector_data:
if (
+ line.startswith("# PSS Example") or
+ line.startswith("# PKCS#1 v1.5 Signature")
+ ):
+ if example_vector:
+ for key, value in six.iteritems(example_vector):
+ hex_str = "".join(value).replace(" ", "")
+ example_vector[key] = hex_str
+ examples.append(example_vector)
+
+ attr = None
+ example_vector = collections.defaultdict(list)
+
+ if line.startswith("# Message to be signed"):
+ attr = "message"
+ continue
+ elif line.startswith("# Salt"):
+ attr = "salt"
+ continue
+ elif line.startswith("# Signature"):
+ attr = "signature"
+ continue
+ elif (
+ example_vector and
+ line.startswith("# =============================================")
+ ):
+ for key, value in six.iteritems(example_vector):
+ hex_str = "".join(value).replace(" ", "")
+ example_vector[key] = hex_str
+ examples.append(example_vector)
+ example_vector = None
+ attr = None
+ elif example_vector and line.startswith("#"):
+ continue
+ else:
+ if attr is not None and example_vector is not None:
+ example_vector[attr].append(line.strip())
+ continue
+
+ if (
line.startswith("# Example") or
line.startswith("# =============================================")
):
@@ -202,6 +241,9 @@ def load_pkcs1_vectors(vector_data):
hex_str = "".join(value).replace(" ", "")
private_key_vector[key] = int(hex_str, 16)
+ private_key_vector["examples"] = examples
+ examples = []
+
assert (
private_key_vector['public_exponent'] ==
public_key_vector['public_exponent']