mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-10 22:05:37 +00:00
Readability improvements
No indented semantic change.
This commit is contained in:
parent
8096969905
commit
5c196fb599
|
@ -205,9 +205,12 @@ class MacroCollector:
|
||||||
self.key_usages = set()
|
self.key_usages = set()
|
||||||
|
|
||||||
# "#define" followed by a macro name with either no parameters
|
# "#define" followed by a macro name with either no parameters
|
||||||
# or a single parameter. Grab the macro name in group 1, the
|
# or a single parameter and a non-empty expansion.
|
||||||
# parameter name if any in group 2 and the definition in group 3.
|
# Grab the macro name in group 1, the parameter name if any in group 2
|
||||||
definition_re = re.compile(r'\s*#\s*define\s+(\w+)(?:\s+|\((\w+)\)\s*)(.+)(?:/[*/])?')
|
# and the expansion in group 3.
|
||||||
|
_define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' +
|
||||||
|
r'(?:\s+|\((\w+)\)\s*)' +
|
||||||
|
r'(.+)(?:/[*/])?')
|
||||||
|
|
||||||
def read_line(self, line):
|
def read_line(self, line):
|
||||||
"""Parse a C header line and record the PSA identifier it defines if any.
|
"""Parse a C header line and record the PSA identifier it defines if any.
|
||||||
|
@ -215,10 +218,10 @@ class MacroCollector:
|
||||||
(up to non-significant whitespace) and skips all non-matching lines.
|
(up to non-significant whitespace) and skips all non-matching lines.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches
|
# pylint: disable=too-many-branches
|
||||||
m = re.match(self.definition_re, line)
|
m = re.match(self._define_directive_re, line)
|
||||||
if not m:
|
if not m:
|
||||||
return
|
return
|
||||||
name, parameter, definition = m.groups()
|
name, parameter, expansion = m.groups()
|
||||||
if name.endswith('_FLAG') or name.endswith('MASK'):
|
if name.endswith('_FLAG') or name.endswith('MASK'):
|
||||||
# Macro only to build actual values
|
# Macro only to build actual values
|
||||||
return
|
return
|
||||||
|
@ -251,10 +254,10 @@ class MacroCollector:
|
||||||
return
|
return
|
||||||
self.algorithms.add(name)
|
self.algorithms.add(name)
|
||||||
# Ad hoc detection of hash algorithms
|
# Ad hoc detection of hash algorithms
|
||||||
if re.search(r'0x010000[0-9A-Fa-f]{2}', definition):
|
if re.search(r'0x010000[0-9A-Fa-f]{2}', expansion):
|
||||||
self.hash_algorithms.add(name)
|
self.hash_algorithms.add(name)
|
||||||
# Ad hoc detection of key agreement algorithms
|
# Ad hoc detection of key agreement algorithms
|
||||||
if re.search(r'0x30[0-9A-Fa-f]{2}0000', definition):
|
if re.search(r'0x30[0-9A-Fa-f]{2}0000', expansion):
|
||||||
self.ka_algorithms.add(name)
|
self.ka_algorithms.add(name)
|
||||||
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']:
|
if name in ['PSA_ALG_DSA', 'PSA_ALG_ECDSA']:
|
||||||
|
|
|
@ -159,19 +159,24 @@ class Inputs:
|
||||||
# Regex of macro names to exclude.
|
# Regex of macro names to exclude.
|
||||||
_excluded_name_re = re.compile(r'_(?:GET|IS|OF)_|_(?:BASE|FLAG|MASK)\Z')
|
_excluded_name_re = re.compile(r'_(?:GET|IS|OF)_|_(?:BASE|FLAG|MASK)\Z')
|
||||||
# Additional excluded macros.
|
# Additional excluded macros.
|
||||||
# PSA_ALG_ECDH and PSA_ALG_FFDH are excluded for now as the script
|
_excluded_names = set([
|
||||||
# currently doesn't support them. Deprecated errors are also excluded.
|
# Macros that provide an alternative way to build the same
|
||||||
_excluded_names = set(['PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH',
|
# algorithm as another macro.
|
||||||
'PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE',
|
'PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH',
|
||||||
'PSA_ALG_FULL_LENGTH_MAC',
|
'PSA_ALG_FULL_LENGTH_MAC',
|
||||||
'PSA_ALG_ECDH',
|
# Auxiliary macro whose name doesn't fit the usual patterns for
|
||||||
'PSA_ALG_FFDH',
|
# auxiliary macros.
|
||||||
'PSA_ERROR_UNKNOWN_ERROR',
|
'PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH_CASE',
|
||||||
'PSA_ERROR_OCCUPIED_SLOT',
|
# PSA_ALG_ECDH and PSA_ALG_FFDH are excluded for now as the script
|
||||||
'PSA_ERROR_EMPTY_SLOT',
|
# currently doesn't support them.
|
||||||
'PSA_ERROR_INSUFFICIENT_CAPACITY',
|
'PSA_ALG_ECDH',
|
||||||
])
|
'PSA_ALG_FFDH',
|
||||||
|
# Deprecated aliases.
|
||||||
|
'PSA_ERROR_UNKNOWN_ERROR',
|
||||||
|
'PSA_ERROR_OCCUPIED_SLOT',
|
||||||
|
'PSA_ERROR_EMPTY_SLOT',
|
||||||
|
'PSA_ERROR_INSUFFICIENT_CAPACITY',
|
||||||
|
])
|
||||||
def parse_header_line(self, line):
|
def parse_header_line(self, line):
|
||||||
"""Parse a C header line, looking for "#define PSA_xxx"."""
|
"""Parse a C header line, looking for "#define PSA_xxx"."""
|
||||||
m = re.match(self._header_line_re, line)
|
m = re.match(self._header_line_re, line)
|
||||||
|
|
Loading…
Reference in a new issue