add_test_case_line: data-driven dispatch

No behavior change.
This commit is contained in:
Gilles Peskine 2019-11-21 19:22:45 +01:00
parent 84a45817a4
commit 8c8694c14d

View file

@ -61,6 +61,7 @@ class read_file_lines:
from exc_value from exc_value
class Inputs: class Inputs:
# pylint: disable=too-many-instance-attributes
"""Accumulate information about macros to test. """Accumulate information about macros to test.
This includes macro names as well as information about their arguments This includes macro names as well as information about their arguments
@ -93,6 +94,16 @@ class Inputs:
'KEY_TYPE': self.key_types, 'KEY_TYPE': self.key_types,
'KEY_USAGE': self.key_usage_flags, 'KEY_USAGE': self.key_usage_flags,
} }
# Test functions
self.table_by_test_function = {
'key_type': self.key_types,
'ecc_key_types': self.ecc_curves,
'dh_key_types': self.dh_groups,
'hash_algorithm': self.hash_algorithms,
'mac_algorithm': self.mac_algorithms,
'hmac_algorithm': self.mac_algorithms,
'aead_algorithm': self.aead_algorithms,
}
# macro name -> list of argument names # macro name -> list of argument names
self.argspecs = {} self.argspecs = {}
# argument name -> list of values # argument name -> list of values
@ -220,24 +231,17 @@ class Inputs:
def add_test_case_line(self, function, argument): def add_test_case_line(self, function, argument):
"""Parse a test case data line, looking for algorithm metadata tests.""" """Parse a test case data line, looking for algorithm metadata tests."""
sets = []
if function.endswith('_algorithm'): if function.endswith('_algorithm'):
# As above, ECDH and FFDH algorithms are excluded for now. # As above, ECDH and FFDH algorithms are excluded for now.
# Support for them will be added in the future. # Support for them will be added in the future.
if 'ECDH' in argument or 'FFDH' in argument: if 'ECDH' in argument or 'FFDH' in argument:
return return
self.algorithms.add(argument) sets.append(self.algorithms)
if function == 'hash_algorithm': if function in self.table_by_test_function:
self.hash_algorithms.add(argument) sets.append(self.table_by_test_function[function])
elif function in ['mac_algorithm', 'hmac_algorithm']: for s in sets:
self.mac_algorithms.add(argument) s.add(argument)
elif function == 'aead_algorithm':
self.aead_algorithms.add(argument)
elif function == 'key_type':
self.key_types.add(argument)
elif function == 'ecc_key_types':
self.ecc_curves.add(argument)
elif function == 'dh_key_types':
self.dh_groups.add(argument)
# Regex matching a *.data line containing a test function call and # Regex matching a *.data line containing a test function call and
# its arguments. The actual definition is partly positional, but this # its arguments. The actual definition is partly positional, but this