diff options
| author | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-16 11:59:17 -0700 |
|---|---|---|
| committer | Alex Gaynor <alex.gaynor@gmail.com> | 2013-10-16 11:59:17 -0700 |
| commit | 1fe70b12b24f1180b2c4fde1764e309bc0cb338d (patch) | |
| tree | 0e5ff08c13691675319ff5192deb2ad595e9f895 /tests/utils.py | |
| parent | 1ab3aa47898b70f3329c17854c913e7511486787 (diff) | |
| download | cryptography-1fe70b12b24f1180b2c4fde1764e309bc0cb338d.tar.gz | |
Start of the great refactoring
Diffstat (limited to 'tests/utils.py')
| -rw-r--r-- | tests/utils.py | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/tests/utils.py b/tests/utils.py index d06c9e3ba..222082253 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 |
