aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2013-11-19 07:38:19 -0800
committerAlex Gaynor <alex.gaynor@gmail.com>2013-11-19 07:38:19 -0800
commitb29a6b2e4623fa87fecaccc05551b996f684cd53 (patch)
treef3579a5536862a304eaba25612f07f0c2515c8bd /tests/utils.py
parent867acfa0300ca75f2c11c15490e04b556d8bfe99 (diff)
parent62e96cbb0698d8f7d65d8dd2d301ef975a829d9e (diff)
downloadcryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.gz
cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.tar.bz2
cryptography-b29a6b2e4623fa87fecaccc05551b996f684cd53.zip
Merge branch 'master' into fernet
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py75
1 files changed, 22 insertions, 53 deletions
diff --git a/tests/utils.py b/tests/utils.py
index 99ba2e2f..94f97d59 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -14,58 +14,44 @@
import os.path
-def load_nist_vectors(vector_data, op):
- section, count, data = None, None, {}
+def load_vectors_from_file(filename, loader):
+ base = os.path.join(
+ os.path.dirname(__file__), "hazmat", "primitives", "vectors",
+ )
+ with open(os.path.join(base, filename), "r") as vector_file:
+ return loader(vector_file)
+
+
+def load_nist_vectors(vector_data):
+ test_data = None
+ data = []
for line in vector_data:
line = line.strip()
- # Blank lines are ignored
- if not line:
- continue
-
- # Lines starting with # are comments
- if line.startswith("#"):
+ # Blank lines, comments, and section headers are ignored
+ if not line or line.startswith("#") or (line.startswith("[")
+ and line.endswith("]")):
continue
- # Look for section headers
- if line.startswith("[") and line.endswith("]"):
- section = line[1:-1]
- data[section] = {}
+ if line.strip() == "FAIL":
+ test_data["fail"] = True
continue
# Build our data using a simple Key = Value format
- name, value = line.split(" = ")
+ name, value = [c.strip() for c in line.split("=")]
# COUNT is a special token that indicates a new block of data
if name.upper() == "COUNT":
- count = value
- data[section][count] = {}
+ test_data = {}
+ data.append(test_data)
+ continue
# For all other tokens we simply want the name, value stored in
# the dictionary
else:
- data[section][count][name.lower()] = value.encode("ascii")
-
- # 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):
- base = os.path.join(
- os.path.dirname(__file__), "hazmat", "primitives", "vectors",
- )
- with open(os.path.join(base, filename), "r") as vector_file:
- return load_nist_vectors(vector_file, op)
-
+ test_data[name.lower()] = value.encode("ascii")
-def load_cryptrec_vectors_from_file(filename):
- base = os.path.join(
- os.path.dirname(__file__),
- "hazmat", "primitives", "vectors",
- )
- with open(os.path.join(base, filename), "r") as vector_file:
- return load_cryptrec_vectors(vector_file)
+ return data
def load_cryptrec_vectors(vector_data):
@@ -96,15 +82,6 @@ def load_cryptrec_vectors(vector_data):
return cryptrec_list
-def load_openssl_vectors_from_file(filename):
- base = os.path.join(
- os.path.dirname(__file__),
- "hazmat", "primitives", "vectors",
- )
- with open(os.path.join(base, filename), "r") as vector_file:
- return load_openssl_vectors(vector_file)
-
-
def load_openssl_vectors(vector_data):
vectors = []
@@ -166,11 +143,3 @@ def load_hash_vectors(vector_data):
else:
raise ValueError("Unknown line in hash vector")
return vectors
-
-
-def load_hash_vectors_from_file(filename):
- base = os.path.join(
- os.path.dirname(__file__), "hazmat", "primitives", "vectors"
- )
- with open(os.path.join(base, filename), "r") as vector_file:
- return load_hash_vectors(vector_file)