Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 1 | /* |
2 | * Version feature information | ||||
3 | * | ||||
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 4 | * Copyright The Mbed TLS Contributors |
Dave Rodgman | 16799db | 2023-11-02 19:47:20 +0000 | [diff] [blame] | 5 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 6 | */ |
7 | |||||
Gilles Peskine | db09ef6 | 2020-06-03 01:43:33 +0200 | [diff] [blame] | 8 | #include "common.h" |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 9 | |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 10 | #if defined(MBEDTLS_VERSION_C) |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 11 | |
Manuel Pégourié-Gonnard | 7f80997 | 2015-03-09 17:05:11 +0000 | [diff] [blame] | 12 | #include "mbedtls/version.h" |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 13 | |
14 | #include <string.h> | ||||
15 | |||||
Máté Varga | c5de462 | 2019-06-12 12:26:37 +0200 | [diff] [blame] | 16 | static const char * const features[] = { |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 17 | #if defined(MBEDTLS_VERSION_FEATURES) |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 18 | FEATURE_DEFINES |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 19 | #endif /* MBEDTLS_VERSION_FEATURES */ |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 20 | NULL |
21 | }; | ||||
22 | |||||
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 23 | int mbedtls_version_check_feature(const char *feature) |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 24 | { |
Máté Varga | c5de462 | 2019-06-12 12:26:37 +0200 | [diff] [blame] | 25 | const char * const *idx = features; |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 26 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 27 | if (*idx == NULL) { |
28 | return -2; | ||||
29 | } | ||||
Paul Bakker | 790e395 | 2014-04-30 16:48:32 +0200 | [diff] [blame] | 30 | |
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 31 | if (feature == NULL) { |
32 | return -1; | ||||
33 | } | ||||
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 34 | |
Dave Rodgman | 90dfc21 | 2023-06-14 17:06:53 +0100 | [diff] [blame] | 35 | if (strncmp(feature, "MBEDTLS_", 8)) { |
36 | return -1; | ||||
37 | } | ||||
38 | |||||
39 | feature += 8; | ||||
40 | |||||
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 41 | while (*idx != NULL) { |
42 | if (!strcmp(*idx, feature)) { | ||||
43 | return 0; | ||||
44 | } | ||||
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 45 | idx++; |
46 | } | ||||
Gilles Peskine | 449bd83 | 2023-01-11 14:50:10 +0100 | [diff] [blame] | 47 | return -1; |
Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 48 | } |
49 | |||||
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 50 | #endif /* MBEDTLS_VERSION_C */ |