blob: bae93c366285166f32be31c9ab35e3869b5e4680 [file] [log] [blame]
Gilles Peskine3374f6e2025-07-31 21:09:39 +02001#!/usr/bin/env python3
2
3"""Generate C preprocessor code to check for bad configurations.
4"""
5
Gilles Peskine8e44a942025-09-15 15:27:20 +02006from typing import Iterator
7
Gilles Peskine3374f6e2025-07-31 21:09:39 +02008import framework_scripts_path # pylint: disable=unused-import
9from mbedtls_framework.config_checks_generator import * \
10 #pylint: disable=wildcard-import,unused-wildcard-import
Gilles Peskine8e44a942025-09-15 15:27:20 +020011from mbedtls_framework import config_history
Gilles Peskine3374f6e2025-07-31 21:09:39 +020012
Gilles Peskine24273c02025-07-16 22:27:09 +020013class CryptoInternal(SubprojectInternal):
14 SUBPROJECT = 'TF-PSA-Crypto'
15
16class CryptoOption(SubprojectOption):
17 SUBPROJECT = 'psa/crypto_config.h'
18
Gilles Peskinec45d9ac2025-09-19 22:17:05 +020019ALWAYS_ENABLED_SINCE_4_0 = frozenset([
20 'MBEDTLS_PSA_CRYPTO_CONFIG',
21 'MBEDTLS_USE_PSA_CRYPTO',
22])
23
Gilles Peskine8e44a942025-09-15 15:27:20 +020024def checkers_for_removed_options() -> Iterator[Checker]:
25 """Discover removed options. Yield corresponding checkers."""
26 history = config_history.ConfigHistory()
27 old_public = history.options('mbedtls', '3.6')
28 new_public = history.options('mbedtls', '4.0')
29 crypto_public = history.options('tfpsacrypto', '1.0')
30 crypto_internal = history.internal('tfpsacrypto', '1.0')
31 for option in sorted(old_public - new_public):
Gilles Peskinec45d9ac2025-09-19 22:17:05 +020032 if option in ALWAYS_ENABLED_SINCE_4_0:
33 continue
Gilles Peskine8e44a942025-09-15 15:27:20 +020034 if option in crypto_public:
35 yield CryptoOption(option)
36 elif option in crypto_internal:
37 yield CryptoInternal(option)
38 else:
39 yield Removed(option, 'Mbed TLS 4.0')
40
41def all_checkers() -> Iterator[Checker]:
42 """Yield all checkers."""
43 yield from checkers_for_removed_options()
44
Gilles Peskine3374f6e2025-07-31 21:09:39 +020045MBEDTLS_CHECKS = BranchData(
46 header_directory='library',
47 header_prefix='mbedtls_',
48 project_cpp_prefix='MBEDTLS',
Gilles Peskine8e44a942025-09-15 15:27:20 +020049 checkers=list(all_checkers()),
Gilles Peskine3374f6e2025-07-31 21:09:39 +020050)
51
52if __name__ == '__main__':
53 main(MBEDTLS_CHECKS)