mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-10-26 00:37:41 +03:00
Automatically generate checkers for removed options
Read the list of historical config options in 3.6, compare that to 1.0/4.0 and emit the appropriate checkers. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -3,9 +3,12 @@
|
|||||||
"""Generate C preprocessor code to check for bad configurations.
|
"""Generate C preprocessor code to check for bad configurations.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from typing import Iterator
|
||||||
|
|
||||||
import framework_scripts_path # pylint: disable=unused-import
|
import framework_scripts_path # pylint: disable=unused-import
|
||||||
from mbedtls_framework.config_checks_generator import * \
|
from mbedtls_framework.config_checks_generator import * \
|
||||||
#pylint: disable=wildcard-import,unused-wildcard-import
|
#pylint: disable=wildcard-import,unused-wildcard-import
|
||||||
|
from mbedtls_framework import config_history
|
||||||
|
|
||||||
class CryptoInternal(SubprojectInternal):
|
class CryptoInternal(SubprojectInternal):
|
||||||
SUBPROJECT = 'TF-PSA-Crypto'
|
SUBPROJECT = 'TF-PSA-Crypto'
|
||||||
@@ -13,16 +16,30 @@ class CryptoInternal(SubprojectInternal):
|
|||||||
class CryptoOption(SubprojectOption):
|
class CryptoOption(SubprojectOption):
|
||||||
SUBPROJECT = 'psa/crypto_config.h'
|
SUBPROJECT = 'psa/crypto_config.h'
|
||||||
|
|
||||||
|
def checkers_for_removed_options() -> Iterator[Checker]:
|
||||||
|
"""Discover removed options. Yield corresponding checkers."""
|
||||||
|
history = config_history.ConfigHistory()
|
||||||
|
old_public = history.options('mbedtls', '3.6')
|
||||||
|
new_public = history.options('mbedtls', '4.0')
|
||||||
|
crypto_public = history.options('tfpsacrypto', '1.0')
|
||||||
|
crypto_internal = history.internal('tfpsacrypto', '1.0')
|
||||||
|
for option in sorted(old_public - new_public):
|
||||||
|
if option in crypto_public:
|
||||||
|
yield CryptoOption(option)
|
||||||
|
elif option in crypto_internal:
|
||||||
|
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()
|
||||||
|
|
||||||
MBEDTLS_CHECKS = BranchData(
|
MBEDTLS_CHECKS = BranchData(
|
||||||
header_directory='library',
|
header_directory='library',
|
||||||
header_prefix='mbedtls_',
|
header_prefix='mbedtls_',
|
||||||
project_cpp_prefix='MBEDTLS',
|
project_cpp_prefix='MBEDTLS',
|
||||||
checkers=[
|
checkers=list(all_checkers()),
|
||||||
CryptoInternal('MBEDTLS_MD5_C', 'PSA_WANT_ALG_MD5 in psa/crypto_config.h'),
|
|
||||||
CryptoOption('MBEDTLS_BASE64_C'),
|
|
||||||
Removed('MBEDTLS_KEY_EXCHANGE_RSA_ENABLED', 'Mbed TLS 4.0'),
|
|
||||||
Removed('MBEDTLS_PADLOCK_C', 'Mbed TLS 4.0'),
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class MbedtlsTestConfigChecks(unittest_config_checks.TestConfigChecks):
|
|||||||
"""Error when redundantly setting a subproject internal option."""
|
"""Error when redundantly setting a subproject internal option."""
|
||||||
self.bad_case('#define PSA_WANT_ALG_MD5 1',
|
self.bad_case('#define PSA_WANT_ALG_MD5 1',
|
||||||
'#define MBEDTLS_MD5_C',
|
'#define MBEDTLS_MD5_C',
|
||||||
error=r'MBEDTLS_MD5_C.* PSA_WANT_ALG_MD5 in psa/crypto_config\.h')
|
error=r'MBEDTLS_MD5_C is an internal macro')
|
||||||
|
|
||||||
def test_define_MBEDTLS_MD5_C_added(self) -> None:
|
def test_define_MBEDTLS_MD5_C_added(self) -> None:
|
||||||
"""Error when setting a subproject internal option that was disabled."""
|
"""Error when setting a subproject internal option that was disabled."""
|
||||||
@@ -68,7 +68,7 @@ class MbedtlsTestConfigChecks(unittest_config_checks.TestConfigChecks):
|
|||||||
#undef MBEDTLS_MD5_C
|
#undef MBEDTLS_MD5_C
|
||||||
''',
|
''',
|
||||||
'#define MBEDTLS_MD5_C',
|
'#define MBEDTLS_MD5_C',
|
||||||
error=r'MBEDTLS_MD5_C.* PSA_WANT_ALG_MD5 in psa/crypto_config\.h')
|
error=r'MBEDTLS_MD5_C is an internal macro')
|
||||||
|
|
||||||
def test_define_MBEDTLS_BASE64_C_redundant(self) -> None:
|
def test_define_MBEDTLS_BASE64_C_redundant(self) -> None:
|
||||||
"""Ok to redundantly set a subproject option."""
|
"""Ok to redundantly set a subproject option."""
|
||||||
|
|||||||
Reference in New Issue
Block a user