@@ -205,34 +205,35 @@ def __init__(self):
205
205
self .key_usages = set ()
206
206
207
207
# "#define" followed by a macro name with either no parameters
208
- # or a single parameter. Grab the macro name in group 1, the
209
- # parameter name if any in group 2 and the definition in group 3.
210
- definition_re = re .compile (r'\s*#\s*define\s+(\w+)(?:\s+|\((\w+)\)\s*)(.+)(?:/[*/])?' )
208
+ # or a single parameter and a non-empty expansion.
209
+ # Grab the macro name in group 1, the parameter name if any in group 2
210
+ # and the expansion in group 3.
211
+ _define_directive_re = re .compile (r'\s*#\s*define\s+(\w+)' +
212
+ r'(?:\s+|\((\w+)\)\s*)' +
213
+ r'(.+)' )
214
+ _deprecated_definition_re = re .compile (r'\s*MBEDTLS_DEPRECATED' )
211
215
212
216
def read_line (self , line ):
213
217
"""Parse a C header line and record the PSA identifier it defines if any.
214
218
This function analyzes lines that start with "#define PSA_"
215
219
(up to non-significant whitespace) and skips all non-matching lines.
216
220
"""
217
221
# pylint: disable=too-many-branches
218
- m = re .match (self .definition_re , line )
222
+ m = re .match (self ._define_directive_re , line )
219
223
if not m :
220
224
return
221
- name , parameter , definition = m .groups ()
225
+ name , parameter , expansion = m .groups ()
226
+ expansion = re .sub (r'/\*.*?\*/|//.*' , r' ' , expansion )
227
+ if re .match (self ._deprecated_definition_re , expansion ):
228
+ # Skip deprecated values, which are assumed to be
229
+ # backward compatibility aliases that share
230
+ # numerical values with non-deprecated values.
231
+ return
222
232
if name .endswith ('_FLAG' ) or name .endswith ('MASK' ):
223
233
# Macro only to build actual values
224
234
return
225
235
elif (name .startswith ('PSA_ERROR_' ) or name == 'PSA_SUCCESS' ) \
226
236
and not parameter :
227
- if name in ['PSA_ERROR_UNKNOWN_ERROR' ,
228
- 'PSA_ERROR_OCCUPIED_SLOT' ,
229
- 'PSA_ERROR_EMPTY_SLOT' ,
230
- 'PSA_ERROR_INSUFFICIENT_CAPACITY' ,
231
- ]:
232
- # Ad hoc skipping of deprecated error codes, which share
233
- # numerical values with non-deprecated error codes
234
- return
235
-
236
237
self .statuses .add (name )
237
238
elif name .startswith ('PSA_KEY_TYPE_' ) and not parameter :
238
239
self .key_types .add (name )
@@ -251,10 +252,10 @@ def read_line(self, line):
251
252
return
252
253
self .algorithms .add (name )
253
254
# Ad hoc detection of hash algorithms
254
- if re .search (r'0x010000[0-9A-Fa-f]{2}' , definition ):
255
+ if re .search (r'0x010000[0-9A-Fa-f]{2}' , expansion ):
255
256
self .hash_algorithms .add (name )
256
257
# Ad hoc detection of key agreement algorithms
257
- if re .search (r'0x30[0-9A-Fa-f]{2}0000' , definition ):
258
+ if re .search (r'0x30[0-9A-Fa-f]{2}0000' , expansion ):
258
259
self .ka_algorithms .add (name )
259
260
elif name .startswith ('PSA_ALG_' ) and parameter == 'hash_alg' :
260
261
if name in ['PSA_ALG_DSA' , 'PSA_ALG_ECDSA' ]:
@@ -271,6 +272,9 @@ def read_line(self, line):
271
272
272
273
def read_file (self , header_file ):
273
274
for line in header_file :
275
+ while line .endswith ('\\ \n ' ):
276
+ cont = next (header_file )
277
+ line = line [:- 2 ] + cont
274
278
self .read_line (line )
275
279
276
280
@staticmethod
0 commit comments