Abbreviate descriptions of generated PSA storage tests

This currently makes all the descriptions unambiguous even when truncated at
66 characters, as the unit test framework does.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2022-03-18 00:02:15 +01:00
parent d79aef5f3c
commit 930ccefba0
4 changed files with 4939 additions and 4930 deletions

View File

@ -25,7 +25,7 @@ from typing import Iterable, Optional, Tuple
from mbedtls_dev.asymmetric_key_data import ASYMMETRIC_KEY_DATA from mbedtls_dev.asymmetric_key_data import ASYMMETRIC_KEY_DATA
def short_expression(original: str) -> str: def short_expression(original: str, level: int = 0) -> str:
"""Abbreviate the expression, keeping it human-readable. """Abbreviate the expression, keeping it human-readable.
If `level` is 0, just remove parts that are implicit from context, If `level` is 0, just remove parts that are implicit from context,
@ -36,6 +36,15 @@ def short_expression(original: str) -> str:
short = original short = original
short = re.sub(r'\bPSA_(?:ALG|ECC_FAMILY|KEY_[A-Z]+)_', r'', short) short = re.sub(r'\bPSA_(?:ALG|ECC_FAMILY|KEY_[A-Z]+)_', r'', short)
short = re.sub(r' +', r'', short) short = re.sub(r' +', r'', short)
if level >= 1:
short = re.sub(r'PUBLIC_KEY\b', r'PUB', short)
short = re.sub(r'KEY_PAIR\b', r'PAIR', short)
short = re.sub(r'\bBRAINPOOL_P', r'BP', short)
short = re.sub(r'\bMONTGOMERY\b', r'MGM', short)
short = re.sub(r'AEAD_WITH_SHORTENED_TAG\b', r'AEAD_SHORT', short)
short = re.sub(r'\bDETERMINISTIC_', r'DET_', short)
short = re.sub(r'\bKEY_AGREEMENT\b', r'KA', short)
short = re.sub(r'_PSK_TO_MS\b', r'_PSK2MS', short)
return short return short
@ -118,12 +127,12 @@ class KeyType:
`self.name`. `self.name`.
""" """
def short_expression(self) -> str: def short_expression(self, level: int = 0) -> str:
"""Abbreviate the expression, keeping it human-readable. """Abbreviate the expression, keeping it human-readable.
See `crypto_knowledge.short_expression`. See `crypto_knowledge.short_expression`.
""" """
return short_expression(self.expression) return short_expression(self.expression, level=level)
def is_public(self) -> bool: def is_public(self) -> bool:
"""Whether the key type is for public keys.""" """Whether the key type is for public keys."""
@ -396,12 +405,12 @@ class Algorithm:
return not re.match(r'(?:0[Xx])?0+\s*\Z', kdf_alg) return not re.match(r'(?:0[Xx])?0+\s*\Z', kdf_alg)
def short_expression(self) -> str: def short_expression(self, level: int = 0) -> str:
"""Abbreviate the expression, keeping it human-readable. """Abbreviate the expression, keeping it human-readable.
See `crypto_knowledge.short_expression`. See `crypto_knowledge.short_expression`.
""" """
return short_expression(self.expression) return short_expression(self.expression, level=level)
def can_do(self, category: AlgorithmCategory) -> bool: def can_do(self, category: AlgorithmCategory) -> bool:
"""Whether this algorithm fits the specified operation category.""" """Whether this algorithm fits the specified operation category."""

View File

@ -527,7 +527,7 @@ class StorageFormat:
""" """
verb = 'save' if self.forward else 'read' verb = 'save' if self.forward else 'read'
tc = test_case.TestCase() tc = test_case.TestCase()
tc.set_description('PSA storage {}: {}'.format(verb, key.description)) tc.set_description(verb + ' ' + key.description)
dependencies = automatic_dependencies( dependencies = automatic_dependencies(
key.lifetime.string, key.type.string, key.lifetime.string, key.type.string,
key.alg.string, key.alg2.string, key.alg.string, key.alg2.string,
@ -646,9 +646,9 @@ class StorageFormat:
alg1 = 0 if alg is None else alg.expression #type: psa_storage.Exprable alg1 = 0 if alg is None else alg.expression #type: psa_storage.Exprable
alg2 = 0 alg2 = 0
key_material = kt.key_material(bits) key_material = kt.key_material(bits)
description = 'type: {} {}-bit'.format(kt.short_expression(), bits) description = 'type: {} {}-bit'.format(kt.short_expression(1), bits)
if alg is not None: if alg is not None:
description += ', ' + alg.short_expression() description += ', ' + alg.short_expression(1)
key = StorageTestData(version=self.version, key = StorageTestData(version=self.version,
id=1, lifetime=0x00000001, id=1, lifetime=0x00000001,
type=kt.expression, bits=bits, type=kt.expression, bits=bits,
@ -691,7 +691,7 @@ class StorageFormat:
# whether the key read from storage is suitable for an operation. # whether the key read from storage is suitable for an operation.
# `keys_for_types` generate read tests with an algorithm and a # `keys_for_types` generate read tests with an algorithm and a
# compatible key. # compatible key.
descr = crypto_knowledge.short_expression(alg) descr = crypto_knowledge.short_expression(alg, 1)
usage = ['PSA_KEY_USAGE_EXPORT'] usage = ['PSA_KEY_USAGE_EXPORT']
key1 = StorageTestData(version=self.version, key1 = StorageTestData(version=self.version,
id=1, lifetime=0x00000001, id=1, lifetime=0x00000001,
@ -770,9 +770,9 @@ class StorageFormatV0(StorageFormat):
expected_usage_flags = material_usage_flags + [implicit_usage] expected_usage_flags = material_usage_flags + [implicit_usage]
alg2 = 0 alg2 = 0
key_material = key_type.key_material(bits) key_material = key_type.key_material(bits)
usage_expression = crypto_knowledge.short_expression(implyer_usage) usage_expression = crypto_knowledge.short_expression(implyer_usage, 1)
alg_expression = crypto_knowledge.short_expression(alg) alg_expression = crypto_knowledge.short_expression(alg, 1)
key_type_expression = key_type.short_expression() key_type_expression = key_type.short_expression(1)
description = 'implied by {}: {} {} {}-bit'.format( description = 'implied by {}: {} {} {}-bit'.format(
usage_expression, alg_expression, key_type_expression, bits) usage_expression, alg_expression, key_type_expression, bits)
key = StorageTestData(version=self.version, key = StorageTestData(version=self.version,

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff