From 2e85a925b49e566776585f35a7c0653510d84262 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 16 Jul 2018 11:18:33 -0400 Subject: Refs #3331 -- added initial wycheproof integration, starting with x25519, rsa, and keywrap (#4310) * Refs #3331 -- added initial wycheproof integration, starting with x25519 tests --- tests/utils.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/utils.py') 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 "".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) -- cgit v1.2.3