From efca28007009163b29443c2f5558221f37002bf9 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 17 Feb 2014 20:55:13 -0600 Subject: expand pkcs1 loader to load PKCS1 v1.5 and PSS signature examples --- tests/utils.py | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index 3c150a2e..bcd915be 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -177,15 +177,53 @@ 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 = "msg" + 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 +240,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'] -- cgit v1.2.3 From 7774a0380b551266fc2c6440895c1f17a6e937ee Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Mon, 17 Feb 2014 22:56:55 -0600 Subject: fix pep8 --- tests/utils.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index bcd915be..5262b733 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -186,9 +186,10 @@ def load_pkcs1_vectors(vector_data): examples = [] vectors = [] for line in vector_data: - if (line.startswith("# PSS Example") or - line.startswith("# PKCS#1 v1.5 Signature") - ): + 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(" ", "") -- cgit v1.2.3 From 7d9c306cd6bd1a3250d7b85e812b9cb90aaa3fd3 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 18 Feb 2014 08:27:39 -0600 Subject: rename msg -> message in pkcs1 loader --- tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index 5262b733..6679e907 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -200,7 +200,7 @@ def load_pkcs1_vectors(vector_data): example_vector = collections.defaultdict(list) if line.startswith("# Message to be signed"): - attr = "msg" + attr = "message" continue elif line.startswith("# Salt"): attr = "salt" -- cgit v1.2.3