From 33b84f4db7cf33dbc486b937e423865b84b1e165 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Fri, 17 May 2019 12:05:59 +0200 Subject: [PATCH] Omit all deprecated definitions rather than a hard-coded list Rather than hard-coding a list of deprecated aliases, assume that anything that's deprecated is an alias or otherwise not desired. --- scripts/generate_psa_constants.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index a3cd130a05..c2d2558094 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -211,6 +211,7 @@ class MacroCollector: _define_directive_re = re.compile(r'\s*#\s*define\s+(\w+)' + r'(?:\s+|\((\w+)\)\s*)' + r'(.+)') + _deprecated_definition_re = re.compile(r'\s*MBEDTLS_DEPRECATED') def read_line(self, line): """Parse a C header line and record the PSA identifier it defines if any. @@ -223,20 +224,16 @@ class MacroCollector: return name, parameter, expansion = m.groups() expansion = re.sub(r'/\*.*?\*/|//.*', r' ', expansion) + if re.match(self._deprecated_definition_re, expansion): + # Skip deprecated values, which are assumed to be + # backward compatibility aliases that share + # numerical values with non-deprecated values. + return if name.endswith('_FLAG') or name.endswith('MASK'): # Macro only to build actual values return elif (name.startswith('PSA_ERROR_') or name == 'PSA_SUCCESS') \ and not parameter: - if name in ['PSA_ERROR_UNKNOWN_ERROR', - 'PSA_ERROR_OCCUPIED_SLOT', - 'PSA_ERROR_EMPTY_SLOT', - 'PSA_ERROR_INSUFFICIENT_CAPACITY', - ]: - # Ad hoc skipping of deprecated error codes, which share - # numerical values with non-deprecated error codes - return - self.statuses.add(name) elif name.startswith('PSA_KEY_TYPE_') and not parameter: self.key_types.add(name)