mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-12 22:15:36 +00:00
Break out algorithm_tester() as a separate method
No intended behavior change. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
460d779773
commit
3545103fd4
|
@ -232,6 +232,25 @@ class PSAMacroCollector(PSAMacroEnumerator):
|
||||||
self.key_types_from_group = {} #type: Dict[str, str]
|
self.key_types_from_group = {} #type: Dict[str, str]
|
||||||
self.algorithms_from_hash = {} #type: Dict[str, str]
|
self.algorithms_from_hash = {} #type: Dict[str, str]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def algorithm_tester(name: str) -> str:
|
||||||
|
"""The predicate for whether an algorithm is built from the given constructor.
|
||||||
|
|
||||||
|
The given name must be the name of an algorithm constructor of the
|
||||||
|
form ``PSA_ALG_xxx`` which is used as ``PSA_ALG_xxx(yyy)`` to build
|
||||||
|
an algorithm value. Return the corresponding predicate macro which
|
||||||
|
is used as ``predicate(alg)`` to test whether ``alg`` can be built
|
||||||
|
as ``PSA_ALG_xxx(yyy)``. The predicate is usually called
|
||||||
|
``PSA_ALG_IS_xxx``.
|
||||||
|
"""
|
||||||
|
prefix = 'PSA_ALG_'
|
||||||
|
assert name.startswith(prefix)
|
||||||
|
midfix = 'IS_'
|
||||||
|
suffix = name[len(prefix):]
|
||||||
|
if suffix in ['DSA', 'ECDSA']:
|
||||||
|
midfix += 'RANDOMIZED_'
|
||||||
|
return prefix + midfix + suffix
|
||||||
|
|
||||||
def record_algorithm_subtype(self, name: str, expansion: str) -> None:
|
def record_algorithm_subtype(self, name: str, expansion: str) -> None:
|
||||||
"""Record the subtype of an algorithm constructor.
|
"""Record the subtype of an algorithm constructor.
|
||||||
|
|
||||||
|
@ -307,12 +326,7 @@ class PSAMacroCollector(PSAMacroEnumerator):
|
||||||
self.algorithms.add(name)
|
self.algorithms.add(name)
|
||||||
self.record_algorithm_subtype(name, expansion)
|
self.record_algorithm_subtype(name, expansion)
|
||||||
elif name.startswith('PSA_ALG_') and parameter == 'hash_alg':
|
elif name.startswith('PSA_ALG_') and parameter == 'hash_alg':
|
||||||
if name in ['PSA_ALG_DSA', 'PSA_ALG_ECDSA']:
|
self.algorithms_from_hash[name] = self.algorithm_tester(name)
|
||||||
# A naming irregularity
|
|
||||||
tester = name[:8] + 'IS_RANDOMIZED_' + name[8:]
|
|
||||||
else:
|
|
||||||
tester = name[:8] + 'IS_' + name[8:]
|
|
||||||
self.algorithms_from_hash[name] = tester
|
|
||||||
elif name.startswith('PSA_KEY_USAGE_') and not parameter:
|
elif name.startswith('PSA_KEY_USAGE_') and not parameter:
|
||||||
self.key_usage_flags.add(name)
|
self.key_usage_flags.add(name)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue