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 <[email protected]>
This commit is contained in:
Gilles Peskine
2024-12-11 11:13:05 +01:00
parent 05e4ae8bd7
commit 4a134ee89f
2 changed files with 17 additions and 0 deletions
+3
View File
@@ -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:
@@ -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: