From 1fe70b12b24f1180b2c4fde1764e309bc0cb338d Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 16 Oct 2013 11:59:17 -0700 Subject: Start of the great refactoring --- tests/utils.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index d06c9e3b..22208225 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -14,7 +14,7 @@ import os.path -def load_nist_vectors(vector_data, op, fields): +def load_nist_vectors(vector_data, op): section, count, data = None, None, {} for line in vector_data: @@ -44,21 +44,19 @@ def load_nist_vectors(vector_data, op, fields): # For all other tokens we simply want the name, value stored in # the dictionary else: - data[section][count][name.lower()] = value + data[section][count][name.lower()] = value.encode("ascii") - # We want to test only for a particular operation - return [ - tuple(vector[1][f].encode("ascii") for f in fields) - for vector in sorted(data[op].items(), key=lambda v: v[0]) - ] + # We want to test only for a particular operation, we sort them for the + # benefit of the tests of this function. + return [v for k, v in sorted(data[op].items(), key=lambda kv: kv[0])] -def load_nist_vectors_from_file(filename, op, fields): +def load_nist_vectors_from_file(filename, op): base = os.path.join( os.path.dirname(__file__), "primitives", "vectors", "NIST", ) with open(os.path.join(base, filename), "r") as vector_file: - return load_nist_vectors(vector_file, op, fields) + return load_nist_vectors(vector_file, op) def load_cryptrec_vectors_from_file(filename): @@ -87,7 +85,11 @@ def load_cryptrec_vectors(vector_data): ct = line.split(" : ")[1].replace(" ", "").encode("ascii") # after a C is found the K+P+C tuple is complete # there are many P+C pairs for each K - cryptrec_list.append((key, pt, ct)) + cryptrec_list.append({ + "key": key, + "plaintext": pt, + "ciphertext": ct + }) return cryptrec_list -- cgit v1.2.3 From 016eed1cc1cc26ff404ac31ed3858de362ca37f2 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Wed, 16 Oct 2013 14:16:04 -0700 Subject: Ported openssl vector tests --- tests/utils.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'tests/utils.py') diff --git a/tests/utils.py b/tests/utils.py index 22208225..6b1cfd79 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -112,15 +112,10 @@ def load_openssl_vectors(vector_data): continue vector = line.split(":") - params = ( - # key - vector[1].encode("ascii"), - # iv - vector[2].encode("ascii"), - # plaintext - vector[3].encode("ascii"), - # ciphertext - vector[4].encode("ascii") - ) - vectors.append(params) + vectors.append({ + "key": vector[1].encode("ascii"), + "iv": vector[2].encode("ascii"), + "plaintext": vector[3].encode("ascii"), + "ciphertext": vector[4].encode("ascii"), + }) return vectors -- cgit v1.2.3