2025-07-31 21:09:39 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
"""Generate C preprocessor code to check for bad configurations.
|
|
|
|
|
"""
|
|
|
|
|
|
2025-09-15 15:27:20 +02:00
|
|
|
from typing import Iterator
|
|
|
|
|
|
2025-07-31 21:09:39 +02:00
|
|
|
import framework_scripts_path # pylint: disable=unused-import
|
|
|
|
|
from mbedtls_framework.config_checks_generator import * \
|
|
|
|
|
#pylint: disable=wildcard-import,unused-wildcard-import
|
2025-12-23 12:44:59 +01:00
|
|
|
from mbedtls_framework import config_macros
|
2025-07-31 21:09:39 +02:00
|
|
|
|
2025-07-16 22:27:09 +02:00
|
|
|
class CryptoInternal(SubprojectInternal):
|
|
|
|
|
SUBPROJECT = 'TF-PSA-Crypto'
|
|
|
|
|
|
|
|
|
|
class CryptoOption(SubprojectOption):
|
|
|
|
|
SUBPROJECT = 'psa/crypto_config.h'
|
|
|
|
|
|
2025-09-19 22:17:05 +02:00
|
|
|
ALWAYS_ENABLED_SINCE_4_0 = frozenset([
|
|
|
|
|
'MBEDTLS_PSA_CRYPTO_CONFIG',
|
|
|
|
|
'MBEDTLS_USE_PSA_CRYPTO',
|
|
|
|
|
])
|
|
|
|
|
|
2025-09-15 15:27:20 +02:00
|
|
|
def checkers_for_removed_options() -> Iterator[Checker]:
|
|
|
|
|
"""Discover removed options. Yield corresponding checkers."""
|
2025-12-23 12:44:59 +01:00
|
|
|
previous_major = config_macros.History('mbedtls', '3.6')
|
|
|
|
|
this_major = config_macros.History('mbedtls', '4.0')
|
|
|
|
|
old_public = previous_major.options()
|
|
|
|
|
new_public = this_major.options()
|
|
|
|
|
crypto = config_macros.History('tfpsacrypto', '1.0')
|
2025-09-15 15:27:20 +02:00
|
|
|
for option in sorted(old_public - new_public):
|
2025-09-19 22:17:05 +02:00
|
|
|
if option in ALWAYS_ENABLED_SINCE_4_0:
|
|
|
|
|
continue
|
2025-12-23 12:44:59 +01:00
|
|
|
if option in crypto.options():
|
2025-09-15 15:27:20 +02:00
|
|
|
yield CryptoOption(option)
|
2025-12-23 12:44:59 +01:00
|
|
|
elif option in crypto.internal():
|
2025-09-15 15:27:20 +02:00
|
|
|
yield CryptoInternal(option)
|
|
|
|
|
else:
|
|
|
|
|
yield Removed(option, 'Mbed TLS 4.0')
|
|
|
|
|
|
|
|
|
|
def all_checkers() -> Iterator[Checker]:
|
|
|
|
|
"""Yield all checkers."""
|
|
|
|
|
yield from checkers_for_removed_options()
|
|
|
|
|
|
2025-07-31 21:09:39 +02:00
|
|
|
MBEDTLS_CHECKS = BranchData(
|
|
|
|
|
header_directory='library',
|
|
|
|
|
header_prefix='mbedtls_',
|
|
|
|
|
project_cpp_prefix='MBEDTLS',
|
2025-09-15 15:27:20 +02:00
|
|
|
checkers=list(all_checkers()),
|
2025-07-31 21:09:39 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main(MBEDTLS_CHECKS)
|