From c772b1822ac7be192c5e69b57d75b3d175d3998e Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 12 Jan 2021 15:55:10 +0100 Subject: [PATCH] Move the declaration of query_config() to a dedicated header file Declaring query_config() belongs with the query_config program, not in ssl_test_lib.h, so move the declaration to a new header file query_config.h. Signed-off-by: Gilles Peskine --- programs/Makefile | 12 ++++--- programs/ssl/ssl_test_lib.h | 15 +------- programs/test/query_compile_time_config.c | 2 +- programs/test/query_config.c | 2 ++ programs/test/query_config.h | 42 +++++++++++++++++++++++ scripts/data_files/query_config.fmt | 2 ++ 6 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 programs/test/query_config.h diff --git a/programs/Makefile b/programs/Makefile index 1a2726b43..e0a324f1e 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -268,7 +268,11 @@ ssl/ssl_client1$(EXEXT): ssl/ssl_client1.c $(DEP) $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_client1.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ SSL_TEST_OBJECTS = test/query_config.o ssl/ssl_test_lib.o -SSL_TEST_DEPS = $(SSL_TEST_OBJECTS) ssl/ssl_test_lib.h ssl/ssl_test_common_source.c $(DEP) +SSL_TEST_DEPS = $(SSL_TEST_OBJECTS) \ + test/query_config.h \ + ssl/ssl_test_lib.h \ + ssl/ssl_test_common_source.c \ + $(DEP) ssl/ssl_test_lib.o: ssl/ssl_test_lib.c ssl/ssl_test_lib.h $(DEP) echo " CC ssl/ssl_test_lib.c" @@ -286,7 +290,7 @@ ssl/ssl_server2$(EXEXT): ssl/ssl_server2.c $(SSL_TEST_DEPS) echo " CC ssl/ssl_server2.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_server2.c $(SSL_TEST_OBJECTS) $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -ssl/ssl_context_info$(EXEXT): ssl/ssl_context_info.c test/query_config.o $(DEP) +ssl/ssl_context_info$(EXEXT): ssl/ssl_context_info.c test/query_config.o test/query_config.h $(DEP) echo " CC ssl/ssl_context_info.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ssl/ssl_context_info.c test/query_config.o $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ @@ -314,7 +318,7 @@ test/cpp_dummy_build$(EXEXT): test/cpp_dummy_build.cpp $(DEP) echo " CXX test/cpp_dummy_build.cpp" $(CXX) $(LOCAL_CXXFLAGS) $(CXXFLAGS) test/cpp_dummy_build.cpp $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -test/query_config.o: test/query_config.c $(DEP) +test/query_config.o: test/query_config.c test/query_config.h $(DEP) echo " CC test/query_config.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) -c test/query_config.c -o $@ @@ -330,7 +334,7 @@ test/zeroize$(EXEXT): test/zeroize.c $(DEP) echo " CC test/zeroize.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/zeroize.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -test/query_compile_time_config$(EXEXT): test/query_compile_time_config.c test/query_config.o $(DEP) +test/query_compile_time_config$(EXEXT): test/query_compile_time_config.c test/query_config.o test/query_config.h $(DEP) echo " CC test/query_compile_time_config.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) test/query_compile_time_config.c test/query_config.o $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ diff --git a/programs/ssl/ssl_test_lib.h b/programs/ssl/ssl_test_lib.h index 666e694c9..031c872bd 100644 --- a/programs/ssl/ssl_test_lib.h +++ b/programs/ssl/ssl_test_lib.h @@ -83,20 +83,7 @@ #include -/** Check whether a given configuration symbol is enabled. - * - * \param config The symbol to query (e.g. "MBEDTLS_RSA_C"). - * \return \c 0 if the symbol was defined at compile time - * (in MBEDTLS_CONFIG_FILE or config.h), - * \c 1 otherwise. - * - * \note This function is defined in `programs/test/query_config.c` - * which is automatically generated by - * `scripts/generate_query_config.pl`. - */ -int query_config( const char *config ); - - +#include "../test/query_config.h" #if defined(MBEDTLS_SSL_EXPORT_KEYS) diff --git a/programs/test/query_compile_time_config.c b/programs/test/query_compile_time_config.c index abe8f7607..0e356c822 100644 --- a/programs/test/query_compile_time_config.c +++ b/programs/test/query_compile_time_config.c @@ -40,7 +40,7 @@ "Mbed TLS build and the macro expansion of that configuration will be\n" \ "printed (if any). Otherwise, 1 will be returned.\n" -int query_config( const char *config ); +#include "query_config.h" int main( int argc, char *argv[] ) { diff --git a/programs/test/query_config.c b/programs/test/query_config.c index 1345b11fe..d15c7e9bb 100644 --- a/programs/test/query_config.c +++ b/programs/test/query_config.c @@ -23,6 +23,8 @@ #include MBEDTLS_CONFIG_FILE #endif +#include "query_config.h" + #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else diff --git a/programs/test/query_config.h b/programs/test/query_config.h new file mode 100644 index 000000000..23009c46a --- /dev/null +++ b/programs/test/query_config.h @@ -0,0 +1,42 @@ +/* + * Query Mbed TLS compile time configurations from config.h + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_PROGRAMS_TEST_QUERY_CONFIG_H +#define MBEDTLS_PROGRAMS_TEST_QUERY_CONFIG_H + +#if !defined(MBEDTLS_CONFIG_FILE) +#include "mbedtls/config.h" +#else +#include MBEDTLS_CONFIG_FILE +#endif + +/** Check whether a given configuration symbol is enabled. + * + * \param config The symbol to query (e.g. "MBEDTLS_RSA_C"). + * \return \c 0 if the symbol was defined at compile time + * (in MBEDTLS_CONFIG_FILE or config.h), + * \c 1 otherwise. + * + * \note This function is defined in `programs/test/query_config.c` + * which is automatically generated by + * `scripts/generate_query_config.pl`. + */ +int query_config( const char *config ); + +#endif /* MBEDTLS_PROGRAMS_TEST_QUERY_CONFIG_H */ diff --git a/scripts/data_files/query_config.fmt b/scripts/data_files/query_config.fmt index be1faef65..be541cb48 100644 --- a/scripts/data_files/query_config.fmt +++ b/scripts/data_files/query_config.fmt @@ -23,6 +23,8 @@ #include MBEDTLS_CONFIG_FILE #endif +#include "query_config.h" + #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else