mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-12-25 15:25:27 +00:00
Add some type annotations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
6f7ba5f9c4
commit
10ab267afb
|
@ -17,12 +17,13 @@
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
from typing import Dict, Set
|
||||||
|
|
||||||
class PSAMacroCollector:
|
class PSAMacroCollector:
|
||||||
"""Collect PSA crypto macro definitions from C header files.
|
"""Collect PSA crypto macro definitions from C header files.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, include_intermediate=False):
|
def __init__(self, include_intermediate: bool = False) -> None:
|
||||||
"""Set up an object to collect PSA macro definitions.
|
"""Set up an object to collect PSA macro definitions.
|
||||||
|
|
||||||
Call the read_file method of the constructed object on each header file.
|
Call the read_file method of the constructed object on each header file.
|
||||||
|
@ -31,19 +32,19 @@ class PSAMacroCollector:
|
||||||
PSA_XXX_BASE that do not designate semantic values.
|
PSA_XXX_BASE that do not designate semantic values.
|
||||||
"""
|
"""
|
||||||
self.include_intermediate = include_intermediate
|
self.include_intermediate = include_intermediate
|
||||||
self.statuses = set()
|
self.statuses = set() #type: Set[str]
|
||||||
self.key_types = set()
|
self.key_types = set() #type: Set[str]
|
||||||
self.key_types_from_curve = {}
|
self.key_types_from_curve = {} #type: Dict[str, str]
|
||||||
self.key_types_from_group = {}
|
self.key_types_from_group = {} #type: Dict[str, str]
|
||||||
self.ecc_curves = set()
|
self.ecc_curves = set() #type: Set[str]
|
||||||
self.dh_groups = set()
|
self.dh_groups = set() #type: Set[str]
|
||||||
self.algorithms = set()
|
self.algorithms = set() #type: Set[str]
|
||||||
self.hash_algorithms = set()
|
self.hash_algorithms = set() #type: Set[str]
|
||||||
self.ka_algorithms = set()
|
self.ka_algorithms = set() #type: Set[str]
|
||||||
self.algorithms_from_hash = {}
|
self.algorithms_from_hash = {} #type: Dict[str, str]
|
||||||
self.key_usages = set()
|
self.key_usages = set() #type: Set[str]
|
||||||
|
|
||||||
def is_internal_name(self, name):
|
def is_internal_name(self, name: str) -> bool:
|
||||||
"""Whether this is an internal macro. Internal macros will be skipped."""
|
"""Whether this is an internal macro. Internal macros will be skipped."""
|
||||||
if not self.include_intermediate:
|
if not self.include_intermediate:
|
||||||
if name.endswith('_BASE') or name.endswith('_NONE'):
|
if name.endswith('_BASE') or name.endswith('_NONE'):
|
||||||
|
|
|
@ -29,6 +29,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
from typing import Dict, Iterable, Iterator, List, Set
|
||||||
|
|
||||||
import scripts_path # pylint: disable=unused-import
|
import scripts_path # pylint: disable=unused-import
|
||||||
from mbedtls_dev import c_build_helper
|
from mbedtls_dev import c_build_helper
|
||||||
|
@ -46,31 +47,31 @@ class PSAMacroEnumerator:
|
||||||
enumerated here.
|
enumerated here.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self) -> None:
|
||||||
"""Set up an empty set of known constructor macros.
|
"""Set up an empty set of known constructor macros.
|
||||||
"""
|
"""
|
||||||
self.statuses = set()
|
self.statuses = set() #type: Set[str]
|
||||||
self.algorithms = set()
|
self.algorithms = set() #type: Set[str]
|
||||||
self.ecc_curves = set()
|
self.ecc_curves = set() #type: Set[str]
|
||||||
self.dh_groups = set()
|
self.dh_groups = set() #type: Set[str]
|
||||||
self.key_types = set()
|
self.key_types = set() #type: Set[str]
|
||||||
self.key_usage_flags = set()
|
self.key_usage_flags = set() #type: Set[str]
|
||||||
self.hash_algorithms = set()
|
self.hash_algorithms = set() #type: Set[str]
|
||||||
self.mac_algorithms = set()
|
self.mac_algorithms = set() #type: Set[str]
|
||||||
self.ka_algorithms = set()
|
self.ka_algorithms = set() #type: Set[str]
|
||||||
self.kdf_algorithms = set()
|
self.kdf_algorithms = set() #type: Set[str]
|
||||||
self.aead_algorithms = set()
|
self.aead_algorithms = set() #type: Set[str]
|
||||||
# macro name -> list of argument names
|
# macro name -> list of argument names
|
||||||
self.argspecs = {}
|
self.argspecs = {} #type: Dict[str, List[str]]
|
||||||
# argument name -> list of values
|
# argument name -> list of values
|
||||||
self.arguments_for = {
|
self.arguments_for = {
|
||||||
'mac_length': [],
|
'mac_length': [],
|
||||||
'min_mac_length': [],
|
'min_mac_length': [],
|
||||||
'tag_length': [],
|
'tag_length': [],
|
||||||
'min_tag_length': [],
|
'min_tag_length': [],
|
||||||
}
|
} #type: Dict[str, List[str]]
|
||||||
|
|
||||||
def gather_arguments(self):
|
def gather_arguments(self) -> None:
|
||||||
"""Populate the list of values for macro arguments.
|
"""Populate the list of values for macro arguments.
|
||||||
|
|
||||||
Call this after parsing all the inputs.
|
Call this after parsing all the inputs.
|
||||||
|
@ -84,16 +85,16 @@ class PSAMacroEnumerator:
|
||||||
self.arguments_for['group'] = sorted(self.dh_groups)
|
self.arguments_for['group'] = sorted(self.dh_groups)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format_arguments(name, arguments):
|
def _format_arguments(name: str, arguments: Iterable[str]) -> str:
|
||||||
"""Format a macro call with arguments.."""
|
"""Format a macro call with arguments.."""
|
||||||
return name + '(' + ', '.join(arguments) + ')'
|
return name + '(' + ', '.join(arguments) + ')'
|
||||||
|
|
||||||
_argument_split_re = re.compile(r' *, *')
|
_argument_split_re = re.compile(r' *, *')
|
||||||
@classmethod
|
@classmethod
|
||||||
def _argument_split(cls, arguments):
|
def _argument_split(cls, arguments: str) -> List[str]:
|
||||||
return re.split(cls._argument_split_re, arguments)
|
return re.split(cls._argument_split_re, arguments)
|
||||||
|
|
||||||
def distribute_arguments(self, name):
|
def distribute_arguments(self, name: str) -> Iterator[str]:
|
||||||
"""Generate macro calls with each tested argument set.
|
"""Generate macro calls with each tested argument set.
|
||||||
|
|
||||||
If name is a macro without arguments, just yield "name".
|
If name is a macro without arguments, just yield "name".
|
||||||
|
@ -123,7 +124,7 @@ class PSAMacroEnumerator:
|
||||||
except BaseException as e:
|
except BaseException as e:
|
||||||
raise Exception('distribute_arguments({})'.format(name)) from e
|
raise Exception('distribute_arguments({})'.format(name)) from e
|
||||||
|
|
||||||
def generate_expressions(self, names):
|
def generate_expressions(self, names: Iterable[str]) -> Iterator[str]:
|
||||||
"""Generate expressions covering values constructed from the given names.
|
"""Generate expressions covering values constructed from the given names.
|
||||||
|
|
||||||
`names` can be any iterable collection of macro names.
|
`names` can be any iterable collection of macro names.
|
||||||
|
|
Loading…
Reference in a new issue