mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 01:25:33 +00:00
Use builder method pattern to generate a key
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
This commit is contained in:
parent
9774dcf592
commit
0996080652
69
tests/scripts/generate_psa_tests.py
Executable file → Normal file
69
tests/scripts/generate_psa_tests.py
Executable file → Normal file
|
@ -230,6 +230,12 @@ class StorageKey(psa_storage.Key):
|
||||||
def __init__(self, *, description: str, **kwargs) -> None:
|
def __init__(self, *, description: str, **kwargs) -> None:
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.description = description #type: str
|
self.description = description #type: str
|
||||||
|
class StorageKeyBuilder:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def build(self, **kwargs) -> StorageKey:
|
||||||
|
return StorageKey(**kwargs)
|
||||||
|
|
||||||
class StorageFormat:
|
class StorageFormat:
|
||||||
"""Storage format stability test cases."""
|
"""Storage format stability test cases."""
|
||||||
|
@ -247,6 +253,7 @@ class StorageFormat:
|
||||||
self.constructors = info.constructors #type: macro_collector.PSAMacroEnumerator
|
self.constructors = info.constructors #type: macro_collector.PSAMacroEnumerator
|
||||||
self.version = version #type: int
|
self.version = version #type: int
|
||||||
self.forward = forward #type: bool
|
self.forward = forward #type: bool
|
||||||
|
self.key_builder = StorageKeyBuilder() #type: StorageKeyBuilder
|
||||||
|
|
||||||
def make_test_case(self, key: StorageKey) -> test_case.TestCase:
|
def make_test_case(self, key: StorageKey) -> test_case.TestCase:
|
||||||
"""Construct a storage format test case for the given key.
|
"""Construct a storage format test case for the given key.
|
||||||
|
@ -299,12 +306,13 @@ 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 = StorageKey(version=self.version,
|
key = self.key_builder.build(
|
||||||
id=1, lifetime=lifetime,
|
version=self.version,
|
||||||
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
id=1, lifetime=lifetime,
|
||||||
usage='PSA_KEY_USAGE_EXPORT', alg=0, alg2=0,
|
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
||||||
material=b'L',
|
usage='PSA_KEY_USAGE_EXPORT', alg=0, alg2=0,
|
||||||
description=description)
|
material=b'L',
|
||||||
|
description=description)
|
||||||
return key
|
return key
|
||||||
|
|
||||||
def all_keys_for_lifetimes(self) -> List[StorageKey]:
|
def all_keys_for_lifetimes(self) -> List[StorageKey]:
|
||||||
|
@ -333,12 +341,12 @@ class StorageFormat:
|
||||||
if short is None:
|
if short is None:
|
||||||
short = re.sub(r'\bPSA_KEY_USAGE_', r'', usage)
|
short = re.sub(r'\bPSA_KEY_USAGE_', r'', usage)
|
||||||
description = 'usage: ' + short
|
description = 'usage: ' + short
|
||||||
return StorageKey(version=self.version,
|
return self.key_builder.build(version=self.version,
|
||||||
id=1, lifetime=0x00000001,
|
id=1, lifetime=0x00000001,
|
||||||
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
||||||
usage=usage, alg=0, alg2=0,
|
usage=usage, alg=0, alg2=0,
|
||||||
material=b'K',
|
material=b'K',
|
||||||
description=description)
|
description=description)
|
||||||
|
|
||||||
def all_keys_for_usage_flags(self) -> List[StorageKey]:
|
def all_keys_for_usage_flags(self) -> List[StorageKey]:
|
||||||
"""Generate test keys covering usage flags."""
|
"""Generate test keys covering usage flags."""
|
||||||
|
@ -375,12 +383,13 @@ class StorageFormat:
|
||||||
r'',
|
r'',
|
||||||
kt.expression)
|
kt.expression)
|
||||||
description = 'type: {} {}-bit'.format(short_expression, bits)
|
description = 'type: {} {}-bit'.format(short_expression, bits)
|
||||||
keys.append(StorageKey(version=self.version,
|
keys.append(self.key_builder.build(
|
||||||
id=1, lifetime=0x00000001,
|
version=self.version,
|
||||||
type=kt.expression, bits=bits,
|
id=1, lifetime=0x00000001,
|
||||||
usage=usage_flags, alg=alg, alg2=alg2,
|
type=kt.expression, bits=bits,
|
||||||
material=key_material,
|
usage=usage_flags, alg=alg, alg2=alg2,
|
||||||
description=description))
|
material=key_material,
|
||||||
|
description=description))
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
def all_keys_for_types(self) -> List[StorageKey]:
|
def all_keys_for_types(self) -> List[StorageKey]:
|
||||||
|
@ -397,18 +406,18 @@ class StorageFormat:
|
||||||
descr = re.sub(r'PSA_ALG_', r'', alg)
|
descr = re.sub(r'PSA_ALG_', r'', alg)
|
||||||
descr = re.sub(r',', r', ', re.sub(r' +', r'', descr))
|
descr = re.sub(r',', r', ', re.sub(r' +', r'', descr))
|
||||||
usage = 'PSA_KEY_USAGE_EXPORT'
|
usage = 'PSA_KEY_USAGE_EXPORT'
|
||||||
key1 = StorageKey(version=self.version,
|
key1 = self.key_builder.build(version=self.version,
|
||||||
id=1, lifetime=0x00000001,
|
id=1, lifetime=0x00000001,
|
||||||
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
||||||
usage=usage, alg=alg, alg2=0,
|
usage=usage, alg=alg, alg2=0,
|
||||||
material=b'K',
|
material=b'K',
|
||||||
description='alg: ' + descr)
|
description='alg: ' + descr)
|
||||||
key2 = StorageKey(version=self.version,
|
key2 = self.key_builder.build(version=self.version,
|
||||||
id=1, lifetime=0x00000001,
|
id=1, lifetime=0x00000001,
|
||||||
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
type='PSA_KEY_TYPE_RAW_DATA', bits=8,
|
||||||
usage=usage, alg=0, alg2=alg,
|
usage=usage, alg=0, alg2=alg,
|
||||||
material=b'L',
|
material=b'L',
|
||||||
description='alg2: ' + descr)
|
description='alg2: ' + descr)
|
||||||
return [key1, key2]
|
return [key1, key2]
|
||||||
|
|
||||||
def all_keys_for_algorithms(self) -> List[StorageKey]:
|
def all_keys_for_algorithms(self) -> List[StorageKey]:
|
||||||
|
|
Loading…
Reference in a new issue