blob: 517e81610c4a6eb2c90c4917428f52b3c1f84ba2 [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 Rodgman7ff79652023-11-03 12:04:52 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +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 Peskine1b6c09a2023-01-11 14:52:35 +010027 if (*idx == NULL) {
28 return -2;
29 }
Paul Bakker790e3952014-04-30 16:48:32 +020030
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010031 if (feature == NULL) {
32 return -1;
33 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020034
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010035 while (*idx != NULL) {
36 if (!strcmp(*idx, feature)) {
37 return 0;
38 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020039 idx++;
40 }
Gilles Peskine1b6c09a2023-01-11 14:52:35 +010041 return -1;
Paul Bakker0f90d7d2014-04-30 11:49:44 +020042}
43
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020044#endif /* MBEDTLS_VERSION_C */