aboutsummaryrefslogtreecommitdiffstats
path: root/tests/utils.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2018-07-16 11:18:33 -0400
committerPaul Kehrer <paul.l.kehrer@gmail.com>2018-07-16 20:48:33 +0530
commit2e85a925b49e566776585f35a7c0653510d84262 (patch)
treee6c6242efcab8249cbc56e6db8735e3566b0b96a /tests/utils.py
parentb09b9ecd695187f323c509aecdf517cadcf728d1 (diff)
downloadcryptography-2e85a925b49e566776585f35a7c0653510d84262.tar.gz
cryptography-2e85a925b49e566776585f35a7c0653510d84262.tar.bz2
cryptography-2e85a925b49e566776585f35a7c0653510d84262.zip
Refs #3331 -- added initial wycheproof integration, starting with x25519, rsa, and keywrap (#4310)
* Refs #3331 -- added initial wycheproof integration, starting with x25519 tests
Diffstat (limited to 'tests/utils.py')
-rw-r--r--tests/utils.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/utils.py b/tests/utils.py
index b721f344..ccc3b7c1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -6,7 +6,9 @@ from __future__ import absolute_import, division, print_function
import binascii
import collections
+import json
import math
+import os
import re
from contextlib import contextmanager
@@ -884,3 +886,42 @@ def load_nist_ccm_vectors(vector_data):
test_data[name.lower()] = value.encode("ascii")
return data
+
+
+class WycheproofTest(object):
+ def __init__(self, testgroup, testcase):
+ self.testgroup = testgroup
+ self.testcase = testcase
+
+ def __repr__(self):
+ return "<WycheproofTest({!r}, {!r}, tcId={})>".format(
+ self.testgroup, self.testcase, self.testcase["tcId"],
+ )
+
+ @property
+ def valid(self):
+ return self.testcase["result"] == "valid"
+
+ @property
+ def acceptable(self):
+ return self.testcase["result"] == "acceptable"
+
+ def has_flag(self, flag):
+ return flag in self.testcase["flags"]
+
+
+def skip_if_wycheproof_none(wycheproof):
+ # This is factored into its own function so we can easily test both
+ # branches
+ if wycheproof is None:
+ pytest.skip("--wycheproof-root not provided")
+
+
+def load_wycheproof_tests(wycheproof, test_file):
+ path = os.path.join(wycheproof, "testvectors", test_file)
+ with open(path) as f:
+ data = json.load(f)
+ for group in data["testGroups"]:
+ cases = group.pop("tests")
+ for c in cases:
+ yield WycheproofTest(group, c)