mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-27 06:34:18 +01:00
Fix pylint issues
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
parent
de25402300
commit
b92d61b7e6
41
tests/scripts/generate_psa_tests.py
Executable file → Normal file
41
tests/scripts/generate_psa_tests.py
Executable file → Normal file
@ -248,6 +248,7 @@ class StorageKey(psa_storage.Key):
|
|||||||
self.original_usage #type: psa_storage.Expr
|
self.original_usage #type: psa_storage.Expr
|
||||||
|
|
||||||
class StorageKeyBuilder:
|
class StorageKeyBuilder:
|
||||||
|
# pylint: disable=too-few-public-methods
|
||||||
def __init__(self, usage_extension: bool) -> None:
|
def __init__(self, usage_extension: bool) -> None:
|
||||||
self.usage_extension = usage_extension #type: bool
|
self.usage_extension = usage_extension #type: bool
|
||||||
|
|
||||||
@ -323,8 +324,7 @@ class StorageFormat:
|
|||||||
r'', short)
|
r'', short)
|
||||||
short = re.sub(r'PSA_KEY_[A-Z]+_', r'', short)
|
short = re.sub(r'PSA_KEY_[A-Z]+_', r'', short)
|
||||||
description = 'lifetime: ' + short
|
description = 'lifetime: ' + short
|
||||||
key = self.key_builder.build(
|
key = self.key_builder.build(version=self.version,
|
||||||
version=self.version,
|
|
||||||
id=1, lifetime=lifetime,
|
id=1, lifetime=lifetime,
|
||||||
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
||||||
usage='PSA_KEY_USAGE_EXPORT', alg=0, alg2=0,
|
usage='PSA_KEY_USAGE_EXPORT', alg=0, alg2=0,
|
||||||
@ -367,7 +367,7 @@ class StorageFormat:
|
|||||||
material=b'K',
|
material=b'K',
|
||||||
description=description)
|
description=description)
|
||||||
|
|
||||||
def all_keys_for_usage_flags(
|
def generate_keys_for_usage_flags(
|
||||||
self,
|
self,
|
||||||
extra_desc: Optional[str] = None
|
extra_desc: Optional[str] = None
|
||||||
) -> List[StorageKey]:
|
) -> List[StorageKey]:
|
||||||
@ -405,8 +405,7 @@ class StorageFormat:
|
|||||||
r'',
|
r'',
|
||||||
kt.expression)
|
kt.expression)
|
||||||
description = 'type: {} {}-bit'.format(short_expression, bits)
|
description = 'type: {} {}-bit'.format(short_expression, bits)
|
||||||
keys.append(self.key_builder.build(
|
keys.append(self.key_builder.build(version=self.version,
|
||||||
version=self.version,
|
|
||||||
id=1, lifetime=0x00000001,
|
id=1, lifetime=0x00000001,
|
||||||
type=kt.expression, bits=bits,
|
type=kt.expression, bits=bits,
|
||||||
usage=usage_flags, alg=alg, alg2=alg2,
|
usage=usage_flags, alg=alg, alg2=alg2,
|
||||||
@ -417,7 +416,8 @@ class StorageFormat:
|
|||||||
def all_keys_for_types(self) -> List[StorageKey]:
|
def all_keys_for_types(self) -> List[StorageKey]:
|
||||||
"""Generate test keys covering key types and their representations."""
|
"""Generate test keys covering key types and their representations."""
|
||||||
key_types = sorted(self.constructors.key_types)
|
key_types = sorted(self.constructors.key_types)
|
||||||
return [key for key_type in self.constructors.generate_expressions(key_types)
|
return [key
|
||||||
|
for key_type in self.constructors.generate_expressions(key_types)
|
||||||
for key in self.keys_for_type(key_type)]
|
for key in self.keys_for_type(key_type)]
|
||||||
|
|
||||||
def keys_for_algorithm(self, alg: str) -> List[StorageKey]:
|
def keys_for_algorithm(self, alg: str) -> List[StorageKey]:
|
||||||
@ -445,7 +445,8 @@ class StorageFormat:
|
|||||||
def all_keys_for_algorithms(self) -> List[StorageKey]:
|
def all_keys_for_algorithms(self) -> List[StorageKey]:
|
||||||
"""Generate test keys covering algorithm encodings."""
|
"""Generate test keys covering algorithm encodings."""
|
||||||
algorithms = sorted(self.constructors.algorithms)
|
algorithms = sorted(self.constructors.algorithms)
|
||||||
return [key for alg in self.constructors.generate_expressions(algorithms)
|
return [key
|
||||||
|
for alg in self.constructors.generate_expressions(algorithms)
|
||||||
for key in self.keys_for_algorithm(alg)]
|
for key in self.keys_for_algorithm(alg)]
|
||||||
|
|
||||||
def generate_all_keys(self) -> List[StorageKey]:
|
def generate_all_keys(self) -> List[StorageKey]:
|
||||||
@ -491,7 +492,9 @@ class StorageFormatV0(StorageFormat):
|
|||||||
"""Generate test keys covering usage flags."""
|
"""Generate test keys covering usage flags."""
|
||||||
# First generate keys without usage policy extension for
|
# First generate keys without usage policy extension for
|
||||||
# compatibility testing, then generate the keys with extension
|
# compatibility testing, then generate the keys with extension
|
||||||
# to check the extension is working.
|
# to check the extension is working. Finally generate key for all known
|
||||||
|
# usage flag which needs to be separted because it is not affected by
|
||||||
|
# usage extension.
|
||||||
keys = [] #type: List[StorageKey]
|
keys = [] #type: List[StorageKey]
|
||||||
prev_builder = self.key_builder
|
prev_builder = self.key_builder
|
||||||
|
|
||||||
@ -511,6 +514,7 @@ class StorageFormatV0(StorageFormat):
|
|||||||
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
|
||||||
"""Generate test keys for the specified extendable usage flag,
|
"""Generate test keys for the specified extendable usage flag,
|
||||||
algorithm and key type combination.
|
algorithm and key type combination.
|
||||||
"""
|
"""
|
||||||
@ -531,8 +535,7 @@ class StorageFormatV0(StorageFormat):
|
|||||||
kt.expression)
|
kt.expression)
|
||||||
description = 'extend {}: {} {} {}-bit'.format(
|
description = 'extend {}: {} {} {}-bit'.format(
|
||||||
usage_expression, alg_expression, key_type_expression, bits)
|
usage_expression, alg_expression, key_type_expression, bits)
|
||||||
keys.append(self.key_builder.build(
|
keys.append(self.key_builder.build(version=self.version,
|
||||||
version=self.version,
|
|
||||||
id=1, lifetime=0x00000001,
|
id=1, lifetime=0x00000001,
|
||||||
type=kt.expression, bits=bits,
|
type=kt.expression, bits=bits,
|
||||||
usage=material_usage_flags,
|
usage=material_usage_flags,
|
||||||
@ -543,6 +546,7 @@ class StorageFormatV0(StorageFormat):
|
|||||||
return keys
|
return keys
|
||||||
|
|
||||||
def gather_key_types_for_sign_alg(self) -> Dict[str, List[str]]:
|
def gather_key_types_for_sign_alg(self) -> Dict[str, List[str]]:
|
||||||
|
# pylint: disable=too-many-locals
|
||||||
"""Match possible key types for sign algorithms."""
|
"""Match possible key types for sign algorithms."""
|
||||||
# To create a valid combinaton both the algorithms and key types
|
# To create a valid combinaton both the algorithms and key types
|
||||||
# must be filtered. Pair them with keywords created from its names.
|
# must be filtered. Pair them with keywords created from its names.
|
||||||
@ -555,10 +559,8 @@ class StorageFormatV0(StorageFormat):
|
|||||||
exclusive_keywords = {
|
exclusive_keywords = {
|
||||||
'EDWARDS': 'ECC'
|
'EDWARDS': 'ECC'
|
||||||
}
|
}
|
||||||
key_types = set(self.constructors.generate_expressions(
|
key_types = set(self.constructors.generate_expressions(self.constructors.key_types))
|
||||||
self.constructors.key_types))
|
algorithms = set(self.constructors.generate_expressions(self.constructors.sign_algorithms))
|
||||||
algorithms = set(self.constructors.generate_expressions(
|
|
||||||
self.constructors.sign_algorithms))
|
|
||||||
alg_with_keys = {} #type: Dict[str, List[str]]
|
alg_with_keys = {} #type: Dict[str, List[str]]
|
||||||
translation_table = str.maketrans('(', '_', ')')
|
translation_table = str.maketrans('(', '_', ')')
|
||||||
for alg in algorithms:
|
for alg in algorithms:
|
||||||
@ -605,11 +607,12 @@ class StorageFormatV0(StorageFormat):
|
|||||||
key_restrictions = StorageKey.EXTENDABLE_USAGE_FLAGS_KEY_RESTRICTION
|
key_restrictions = StorageKey.EXTENDABLE_USAGE_FLAGS_KEY_RESTRICTION
|
||||||
# Walk through all combintion. The key types must be filtered to fit
|
# Walk through all combintion. The key types must be filtered to fit
|
||||||
# the specific usage flag.
|
# the specific usage flag.
|
||||||
keys += [key for usage in StorageKey.EXTENDABLE_USAGE_FLAGS.keys()
|
keys += [key
|
||||||
for alg in sorted(alg_with_keys.keys())
|
for usage in StorageKey.EXTENDABLE_USAGE_FLAGS
|
||||||
for key_type in sorted(filter(
|
for alg in sorted(alg_with_keys)
|
||||||
lambda kt: re.match(key_restrictions[usage.string], kt),
|
for key_type in sorted([kt
|
||||||
alg_with_keys[alg]))
|
for kt in alg_with_keys[alg]
|
||||||
|
if re.match(key_restrictions[usage.string], kt)])
|
||||||
for key in self.keys_for_usage_extension(usage, alg, key_type)]
|
for key in self.keys_for_usage_extension(usage, alg, key_type)]
|
||||||
|
|
||||||
self.key_builder = prev_builder
|
self.key_builder = prev_builder
|
||||||
|
Loading…
Reference in New Issue
Block a user