From 4a134ee89f37f07caaef2bc39234b5441654a161 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Thu, 21 Nov 2024 18:33:23 +0100 Subject: [PATCH] psa_test_case automatic dependencies: key pair type operations This fixes the dependencies for key pair types, which have finer-grained dependencies for different operations (BASIC, GENERATE, EXPORT, ...). No changes to the generated output (the new functionality isn't used yet). Signed-off-by: Gilles Peskine --- scripts/generate_psa_tests.py | 3 +++ scripts/mbedtls_framework/psa_test_case.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/scripts/generate_psa_tests.py b/scripts/generate_psa_tests.py index d18411662..0038693a5 100755 --- a/scripts/generate_psa_tests.py +++ b/scripts/generate_psa_tests.py @@ -42,6 +42,7 @@ def test_case_for_key_type_not_supported( .format(verb, short_key_type, bits, adverb)) tc.set_function(verb + '_not_supported') tc.set_key_bits(bits) + tc.set_key_pair_usage(verb.upper()) tc.set_arguments([key_type] + list(args)) tc.set_dependencies(dependencies) tc.skip_if_any_not_implemented(dependencies) @@ -155,6 +156,7 @@ def test_case_for_key_generation( .format(short_key_type, bits)) tc.set_function('generate_key') tc.set_key_bits(bits) + tc.set_key_pair_usage('GENERATE') tc.set_arguments([key_type] + list(args) + [result]) tc.set_dependencies(dependencies) tc.skip_if_any_not_implemented(dependencies) @@ -503,6 +505,7 @@ class StorageFormat: dependencies = psa_information.fix_key_pair_dependencies(dependencies, 'BASIC') tc.set_function('key_storage_' + verb) tc.set_key_bits(key.bits) + tc.set_key_pair_usage('BASIC') if self.forward: extra_arguments = [] else: diff --git a/scripts/mbedtls_framework/psa_test_case.py b/scripts/mbedtls_framework/psa_test_case.py index d478d0ac3..9c52acf6d 100644 --- a/scripts/mbedtls_framework/psa_test_case.py +++ b/scripts/mbedtls_framework/psa_test_case.py @@ -71,6 +71,7 @@ class TestCase(test_case.TestCase): self.automatic_dependencies = set() #type: Set[str] self.dependency_prefix = dependency_prefix #type: Optional[str] self.key_bits = None #type: Optional[int] + self.key_pair_usage = None #type: Optional[str] def set_key_bits(self, key_bits: Optional[int]) -> None: """Use the given key size for automatic dependency generation. @@ -82,6 +83,16 @@ class TestCase(test_case.TestCase): """ self.key_bits = key_bits + def set_key_pair_usage(self, key_pair_usage: Optional[str]) -> None: + """Use the given suffix for key pair dependencies. + + Call this function before set_arguments() if relevant. + + This is only relevant for key pair types. For other key types, + this information is ignored. + """ + self.key_pair_usage = key_pair_usage + def infer_dependencies(self, arguments: List[str]) -> List[str]: """Infer dependencies based on the test case arguments.""" dependencies = psa_information.automatic_dependencies(*arguments, @@ -89,6 +100,9 @@ class TestCase(test_case.TestCase): if self.key_bits is not None: dependencies = psa_information.finish_family_dependencies(dependencies, self.key_bits) + if self.key_pair_usage is not None: + dependencies = psa_information.fix_key_pair_dependencies(dependencies, + self.key_pair_usage) return dependencies def set_arguments(self, arguments: List[str]) -> None: