blob: d820d4d1a72172329122c0c1d031ebfc709a0e3c [file] [log] [blame]
Paul Bakker0f90d7d2014-04-30 11:49:44 +02001/*
2 * Version feature information
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Paul Bakker0f90d7d2014-04-30 11:49:44 +02006 */
7
Gilles Peskinedb09ef62020-06-03 01:43:33 +02008#include "common.h"
Paul Bakker0f90d7d2014-04-30 11:49:44 +02009
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020010#if defined(MBEDTLS_VERSION_C)
Paul Bakker0f90d7d2014-04-30 11:49:44 +020011
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000012#include "mbedtls/version.h"
Paul Bakker0f90d7d2014-04-30 11:49:44 +020013
14#include <string.h>
15
Máté Vargac5de4622019-06-12 12:26:37 +020016static const char * const features[] = {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020017#if defined(MBEDTLS_VERSION_FEATURES)
Gilles Peskine449bd832023-01-11 14:50:10 +010018 FEATURE_DEFINES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020019#endif /* MBEDTLS_VERSION_FEATURES */
Paul Bakker0f90d7d2014-04-30 11:49:44 +020020 NULL
21};
22
Gilles Peskine449bd832023-01-11 14:50:10 +010023int mbedtls_version_check_feature(const char *feature)
Paul Bakker0f90d7d2014-04-30 11:49:44 +020024{
Máté Vargac5de4622019-06-12 12:26:37 +020025 const char * const *idx = features;
Paul Bakker0f90d7d2014-04-30 11:49:44 +020026
Gilles Peskine449bd832023-01-11 14:50:10 +010027 if (*idx == NULL) {
28 return -2;
29 }
Paul Bakker790e3952014-04-30 16:48:32 +020030
Gilles Peskine449bd832023-01-11 14:50:10 +010031 if (feature == NULL) {
32 return -1;
33 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020034
Dave Rodgman90dfc212023-06-14 17:06:53 +010035 if (strncmp(feature, "MBEDTLS_", 8)) {
36 return -1;
37 }
38
39 feature += 8;
40
Gilles Peskine449bd832023-01-11 14:50:10 +010041 while (*idx != NULL) {
42 if (!strcmp(*idx, feature)) {
43 return 0;
44 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020045 idx++;
46 }
Gilles Peskine449bd832023-01-11 14:50:10 +010047 return -1;
Paul Bakker0f90d7d2014-04-30 11:49:44 +020048}
49
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020050#endif /* MBEDTLS_VERSION_C */