generate_psa_tests: optimize code for key pair dependencies generation

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
This commit is contained in:
Valerio Setti 2023-06-29 12:10:52 +02:00
parent c0d2f8417a
commit 0c42c435f1

@ -115,28 +115,33 @@ def hack_dependencies_not_implemented(dependencies: List[str]) -> None:
for dep in dependencies): for dep in dependencies):
dependencies.append('DEPENDENCY_NOT_IMPLEMENTED_YET') dependencies.append('DEPENDENCY_NOT_IMPLEMENTED_YET')
# PSA_WANT_KEY_TYPE_xxx_KEY_PAIR symbols have a GENERATE suffix to state that # This helper function add the proper suffix to PSA_WANT_KEY_TYPE_xxx_KEY_PAIR
# they support key generation. # symbols according to the required usage.
def fix_key_pair_dependencies(dep_list: List[str], usage: str): def tweak_key_pair_dependency(dep: str, usage: str):
ret_list = list()
# Note: this LEGACY replacement for RSA is temporary and it's going to be # Note: this LEGACY replacement for RSA is temporary and it's going to be
# aligned with ECC one in #7772. # aligned with ECC one in #7772.
new_list = [re.sub(r'RSA_KEY_PAIR\Z', r'RSA_KEY_PAIR_LEGACY', dep) if dep.endswith('RSA_KEY_PAIR'):
for dep in dep_list] ret_list.append(re.sub(r'RSA_KEY_PAIR\Z', r'RSA_KEY_PAIR_LEGACY', dep))
new_list = [re.sub(r'ECC_KEY_PAIR\Z', r'ECC_KEY_PAIR_' + usage, dep) elif dep.endswith('ECC_KEY_PAIR'):
for dep in new_list] if usage == "BASIC":
# BASIC automatically includes IMPORT and EXPORT for test purposes (see # BASIC automatically includes IMPORT and EXPORT for test purposes (see
# config_psa.h). # config_psa.h).
if any([re.match(r'[!]?\w+ECC_KEY_PAIR_BASIC', dep) for dep in new_list]): ret_list.append(re.sub(r'ECC_KEY_PAIR', r'ECC_KEY_PAIR_BASIC', dep))
match_pattern = next((dep for dep in new_list ret_list.append(re.sub(r'ECC_KEY_PAIR', r'ECC_KEY_PAIR_IMPORT', dep))
if re.match(r'([!]?\w+ECC_KEY_PAIR_BASIC)', dep) is not None), None) ret_list.append(re.sub(r'ECC_KEY_PAIR', r'ECC_KEY_PAIR_EXPORT', dep))
new_list.append(re.sub(r'ECC_KEY_PAIR_BASIC', r'ECC_KEY_PAIR_IMPORT', match_pattern)) elif usage == "GENERATE":
new_list.append(re.sub(r'ECC_KEY_PAIR_BASIC', r'ECC_KEY_PAIR_EXPORT', match_pattern)) ret_list.append(re.sub(r'ECC_KEY_PAIR', r'ECC_KEY_PAIR_GENERATE', dep))
#if any([re.match(r'!\w+ECC_KEY_PAIR_BASIC\w+', dep) for dep in new_list]): else:
# new_list.append('!PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT') # No replacement to do in this case
# new_list.append('!PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT') ret_list.append(dep)
#elif any([re.match(r'\w+ECC_KEY_PAIR\w+', dep) for dep in new_list]): return ret_list
# new_list.append('PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT')
# new_list.append('PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT') def fix_key_pair_dependencies(dep_list: List[str], usage: str):
new_list = [new_deps
for dep in dep_list
for new_deps in tweak_key_pair_dependency(dep, usage)]
return new_list return new_list
class Information: class Information: