1/* -*-c-*-
2 *  Query Mbed TLS compile time configurations from mbedtls_config.h
3 *
4 *  Copyright The Mbed TLS Contributors
5 *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6 */
7
8#include "mbedtls/build_info.h"
9
10#include "query_config.h"
11
12#include "mbedtls/platform.h"
13#include <string.h>
14
15/* Work around https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/393 */
16#if defined(MBEDTLS_HAVE_TIME)
17#include <mbedtls/platform_time.h>
18#endif
19
20/* *INDENT-OFF* */
21INCLUDE_HEADERS
22/* *INDENT-ON* */
23
24/*
25 * Helper macros to convert a macro or its expansion into a string
26 * WARNING: This does not work for expanding function-like macros. However,
27 * Mbed TLS does not currently have configuration options used in this fashion.
28 */
29#define MACRO_EXPANSION_TO_STR(macro)   MACRO_NAME_TO_STR(macro)
30#define MACRO_NAME_TO_STR(macro)                                        \
31    mbedtls_printf("%s", strlen( #macro "") > 0 ? #macro "\n" : "")
32
33#define STRINGIFY(macro)  #macro
34#define OUTPUT_MACRO_NAME_VALUE(macro) mbedtls_printf( #macro "%s\n",   \
35                                                       (STRINGIFY(macro) "")[0] != 0 ? "=" STRINGIFY( \
36                                                           macro) : "")
37
38#if defined(_MSC_VER)
39/*
40 * Visual Studio throws the warning 4003 because many Mbed TLS feature macros
41 * are defined empty. This means that from the preprocessor's point of view
42 * the macro MBEDTLS_EXPANSION_TO_STR is being invoked without arguments as
43 * some macros expand to nothing. We suppress that specific warning to get a
44 * clean build and to ensure that tests treating warnings as errors do not
45 * fail.
46 */
47#pragma warning(push)
48#pragma warning(disable:4003)
49#endif /* _MSC_VER */
50
51int query_config(const char *config)
52{
53    CHECK_CONFIG /* If the symbol is not found, return an error */
54    return 1;
55}
56
57void list_config(void)
58{
59    LIST_CONFIG
60}
61#if defined(_MSC_VER)
62#pragma warning(pop)
63#endif /* _MSC_VER */
64