diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-09-27 11:26:01 -0500 |
---|---|---|
committer | Paul Kehrer <paul.l.kehrer@gmail.com> | 2013-09-27 11:26:01 -0500 |
commit | e580598228caa28544fdd4fa53a29bb870858421 (patch) | |
tree | e8367bfd3b2ca14650cff8ce38cd4157ba8d6774 /tests/utils.py | |
parent | 6b99a1b6d2e55e41bda5a42357e1b92f2e38d2ab (diff) | |
download | cryptography-e580598228caa28544fdd4fa53a29bb870858421.tar.gz cryptography-e580598228caa28544fdd4fa53a29bb870858421.tar.bz2 cryptography-e580598228caa28544fdd4fa53a29bb870858421.zip |
simplify cryptrec loader, improve comments
Diffstat (limited to 'tests/utils.py')
-rw-r--r-- | tests/utils.py | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/tests/utils.py b/tests/utils.py index 48a32ebe..d06c9e3b 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -70,7 +70,7 @@ def load_cryptrec_vectors_from_file(filename): def load_cryptrec_vectors(vector_data): - data = {} + cryptrec_list = [] for line in vector_data: line = line.strip() @@ -80,28 +80,14 @@ def load_cryptrec_vectors(vector_data): continue if line.startswith("K"): - key = line.split(" : ")[1].replace(" ", "") - # create an array under the key to hold all the P+C pairs - # each key has many p+c pairs - data[key] = [] + key = line.split(" : ")[1].replace(" ", "").encode("ascii") elif line.startswith("P"): - # create a new dict to hold the next P+C pair - pc_pair = {} - pc_pair["P"] = line.split(" : ")[1].replace(" ", "") + pt = line.split(" : ")[1].replace(" ", "").encode("ascii") elif line.startswith("C"): - pc_pair["C"] = line.split(" : ")[1].replace(" ", "") - # after a C is found the P+C pair is complete - data[key].append(pc_pair) - - cryptrec_list = [] - for key, value in sorted(data.items()): - for pair in value: - cryptrec_list.append( - (key.encode("ascii"), - pair["P"].encode("ascii"), - pair["C"].encode("ascii")) - ) - + 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)) return cryptrec_list @@ -124,11 +110,15 @@ def load_openssl_vectors(vector_data): continue vector = line.split(":") - params = (vector[1].encode("ascii"), # key - vector[2].encode("ascii"), # iv - vector[3].encode("ascii"), # ciphertext - vector[4].encode("ascii")) # plaintext - # some OpenSSL vectors have a final field - # 0 for decrypt, 1 for encrypt + params = ( + # key + vector[1].encode("ascii"), + # iv + vector[2].encode("ascii"), + # plaintext + vector[3].encode("ascii"), + # ciphertext + vector[4].encode("ascii") + ) vectors.append(params) return vectors |