Add better name for variables

Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
gabor-mezei-arm 2021-06-28 16:27:29 +02:00
parent 705c452fd0
commit 927742ec71
No known key found for this signature in database
GPG key ID: 106F5A41ECC305BD
2 changed files with 14 additions and 14 deletions

View file

@ -101,18 +101,18 @@ class Key:
LATEST_VERSION = 0 LATEST_VERSION = 0
"""The latest version of the storage format.""" """The latest version of the storage format."""
EXTENDABLE_USAGE_FLAGS = { IMPLICIT_USAGE_FLAGS = {
Expr('PSA_KEY_USAGE_SIGN_HASH'): Expr('PSA_KEY_USAGE_SIGN_MESSAGE'), Expr('PSA_KEY_USAGE_SIGN_HASH'): Expr('PSA_KEY_USAGE_SIGN_MESSAGE'),
Expr('PSA_KEY_USAGE_VERIFY_HASH'): Expr('PSA_KEY_USAGE_VERIFY_MESSAGE') Expr('PSA_KEY_USAGE_VERIFY_HASH'): Expr('PSA_KEY_USAGE_VERIFY_MESSAGE')
} #type: Dict[Expr, Expr] } #type: Dict[Expr, Expr]
"""The extendable usage flags with the corresponding extension flags.""" """Mapping of usage flags to the flags that they imply."""
EXTENDABLE_USAGE_FLAGS_KEY_RESTRICTION = { IMPLICIT_USAGE_FLAGS_KEY_RESTRICTION = {
'PSA_KEY_USAGE_SIGN_HASH': '.*KEY_PAIR', 'PSA_KEY_USAGE_SIGN_HASH': '.*KEY_PAIR',
'PSA_KEY_USAGE_VERIFY_HASH': '.*KEY.*' 'PSA_KEY_USAGE_VERIFY_HASH': '.*KEY.*'
} #type: Dict[str, str] } #type: Dict[str, str]
"""The key type filter for the extendable usage flags. """Use a regexp to determine key types for which signature is possible
The filter is a regexp. when using the actual usage flag.
""" """
def __init__(self, *, def __init__(self, *,
@ -137,7 +137,7 @@ class Key:
self.material = material #type: bytes self.material = material #type: bytes
if usage_extension: if usage_extension:
for flag, extension in self.EXTENDABLE_USAGE_FLAGS.items(): for flag, extension in self.IMPLICIT_USAGE_FLAGS.items():
if self.original_usage.value() & flag.value() and \ if self.original_usage.value() & flag.value() and \
self.original_usage.value() & extension.value() == 0: self.original_usage.value() & extension.value() == 0:
self.updated_usage = Expr(self.updated_usage.string + self.updated_usage = Expr(self.updated_usage.string +

View file

@ -520,25 +520,25 @@ class StorageFormatV0(StorageFormat):
def keys_for_usage_extension( def keys_for_usage_extension(
self, self,
extendable: psa_storage.Expr, implyer_usage: psa_storage.Expr,
alg: str, alg: str,
key_type: str, key_type: str,
params: Optional[Iterable[str]] = None params: Optional[Iterable[str]] = None
) -> List[StorageKey]: ) -> List[StorageKey]:
# pylint: disable=too-many-locals # pylint: disable=too-many-locals
"""Generate test keys for the specified extendable usage flag, """Generate test keys for the specified implicit usage flag,
algorithm and key type combination. algorithm and key type combination.
""" """
keys = [] #type: List[StorageKey] keys = [] #type: List[StorageKey]
kt = crypto_knowledge.KeyType(key_type, params) kt = crypto_knowledge.KeyType(key_type, params)
for bits in kt.sizes_to_test(): for bits in kt.sizes_to_test():
extension = StorageKey.EXTENDABLE_USAGE_FLAGS[extendable] implicit = StorageKey.IMPLICIT_USAGE_FLAGS[implyer_usage]
usage_flags = 'PSA_KEY_USAGE_EXPORT' usage_flags = 'PSA_KEY_USAGE_EXPORT'
material_usage_flags = usage_flags + ' | ' + extendable.string material_usage_flags = usage_flags + ' | ' + implyer_usage.string
expected_usage_flags = material_usage_flags + ' | ' + extension.string expected_usage_flags = material_usage_flags + ' | ' + implicit.string
alg2 = 0 alg2 = 0
key_material = kt.key_material(bits) key_material = kt.key_material(bits)
usage_expression = re.sub(r'PSA_KEY_USAGE_', r'', extendable.string) usage_expression = re.sub(r'PSA_KEY_USAGE_', r'', implyer_usage.string)
alg_expression = re.sub(r'PSA_ALG_', r'', alg) alg_expression = re.sub(r'PSA_ALG_', r'', alg)
alg_expression = re.sub(r',', r', ', re.sub(r' +', r'', alg_expression)) alg_expression = re.sub(r',', r', ', re.sub(r' +', r'', alg_expression))
key_type_expression = re.sub(r'\bPSA_(?:KEY_TYPE|ECC_FAMILY)_', key_type_expression = re.sub(r'\bPSA_(?:KEY_TYPE|ECC_FAMILY)_',
@ -615,11 +615,11 @@ class StorageFormatV0(StorageFormat):
# Generate the keys without usage extension # Generate the keys without usage extension
self.key_builder = StorageKeyBuilder(usage_extension=False) self.key_builder = StorageKeyBuilder(usage_extension=False)
alg_with_keys = self.gather_key_types_for_sign_alg() alg_with_keys = self.gather_key_types_for_sign_alg()
key_filter = StorageKey.EXTENDABLE_USAGE_FLAGS_KEY_RESTRICTION key_filter = StorageKey.IMPLICIT_USAGE_FLAGS_KEY_RESTRICTION
# Use a lookup for the extendable usage flags to able to sort them # Use a lookup for the extendable usage flags to able to sort them
usage_lookup = {} #type: Dict[str, psa_storage.Expr] usage_lookup = {} #type: Dict[str, psa_storage.Expr]
for usage_flag in StorageKey.EXTENDABLE_USAGE_FLAGS: for usage_flag in StorageKey.IMPLICIT_USAGE_FLAGS:
usage_lookup[usage_flag.string] = usage_flag usage_lookup[usage_flag.string] = usage_flag
# Walk through all combintion. The key types must be filtered to fit # Walk through all combintion. The key types must be filtered to fit