Gilles Peskine | 3374f6e | 2025-07-31 21:09:39 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | |
| 3 | """Generate C preprocessor code to check for bad configurations. |
| 4 | """ |
| 5 | |
Gilles Peskine | 8e44a94 | 2025-09-15 15:27:20 +0200 | [diff] [blame] | 6 | from typing import Iterator |
| 7 | |
Gilles Peskine | 3374f6e | 2025-07-31 21:09:39 +0200 | [diff] [blame] | 8 | import framework_scripts_path # pylint: disable=unused-import |
| 9 | from mbedtls_framework.config_checks_generator import * \ |
| 10 | #pylint: disable=wildcard-import,unused-wildcard-import |
Gilles Peskine | 8e44a94 | 2025-09-15 15:27:20 +0200 | [diff] [blame] | 11 | from mbedtls_framework import config_history |
Gilles Peskine | 3374f6e | 2025-07-31 21:09:39 +0200 | [diff] [blame] | 12 | |
Gilles Peskine | 24273c0 | 2025-07-16 22:27:09 +0200 | [diff] [blame] | 13 | class CryptoInternal(SubprojectInternal): |
| 14 | SUBPROJECT = 'TF-PSA-Crypto' |
| 15 | |
| 16 | class CryptoOption(SubprojectOption): |
| 17 | SUBPROJECT = 'psa/crypto_config.h' |
| 18 | |
Gilles Peskine | c45d9ac | 2025-09-19 22:17:05 +0200 | [diff] [blame] | 19 | ALWAYS_ENABLED_SINCE_4_0 = frozenset([ |
| 20 | 'MBEDTLS_PSA_CRYPTO_CONFIG', |
| 21 | 'MBEDTLS_USE_PSA_CRYPTO', |
| 22 | ]) |
| 23 | |
Gilles Peskine | 8e44a94 | 2025-09-15 15:27:20 +0200 | [diff] [blame] | 24 | def 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 Peskine | c45d9ac | 2025-09-19 22:17:05 +0200 | [diff] [blame] | 32 | if option in ALWAYS_ENABLED_SINCE_4_0: |
| 33 | continue |
Gilles Peskine | 8e44a94 | 2025-09-15 15:27:20 +0200 | [diff] [blame] | 34 | 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 | |
| 41 | def all_checkers() -> Iterator[Checker]: |
| 42 | """Yield all checkers.""" |
| 43 | yield from checkers_for_removed_options() |
| 44 | |
Gilles Peskine | 3374f6e | 2025-07-31 21:09:39 +0200 | [diff] [blame] | 45 | MBEDTLS_CHECKS = BranchData( |
| 46 | header_directory='library', |
| 47 | header_prefix='mbedtls_', |
| 48 | project_cpp_prefix='MBEDTLS', |
Gilles Peskine | 8e44a94 | 2025-09-15 15:27:20 +0200 | [diff] [blame] | 49 | checkers=list(all_checkers()), |
Gilles Peskine | 3374f6e | 2025-07-31 21:09:39 +0200 | [diff] [blame] | 50 | ) |
| 51 | |
| 52 | if __name__ == '__main__': |
| 53 | main(MBEDTLS_CHECKS) |