blob: 0e405976014b42d1ba89903f923b74a6abd17f04 [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
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker0f90d7d2014-04-30 11:49:44 +020018 */
19
Gilles Peskinedb09ef62020-06-03 01:43:33 +020020#include "common.h"
Paul Bakker0f90d7d2014-04-30 11:49:44 +020021
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if defined(MBEDTLS_VERSION_C)
Paul Bakker0f90d7d2014-04-30 11:49:44 +020023
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000024#include "mbedtls/version.h"
Paul Bakker0f90d7d2014-04-30 11:49:44 +020025
26#include <string.h>
27
Máté Vargac5de4622019-06-12 12:26:37 +020028static const char * const features[] = {
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029#if defined(MBEDTLS_VERSION_FEATURES)
Gilles Peskine449bd832023-01-11 14:50:10 +010030 FEATURE_DEFINES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020031#endif /* MBEDTLS_VERSION_FEATURES */
Paul Bakker0f90d7d2014-04-30 11:49:44 +020032 NULL
33};
34
Gilles Peskine449bd832023-01-11 14:50:10 +010035int mbedtls_version_check_feature(const char *feature)
Paul Bakker0f90d7d2014-04-30 11:49:44 +020036{
Máté Vargac5de4622019-06-12 12:26:37 +020037 const char * const *idx = features;
Paul Bakker0f90d7d2014-04-30 11:49:44 +020038
Gilles Peskine449bd832023-01-11 14:50:10 +010039 if (*idx == NULL) {
40 return -2;
41 }
Paul Bakker790e3952014-04-30 16:48:32 +020042
Gilles Peskine449bd832023-01-11 14:50:10 +010043 if (feature == NULL) {
44 return -1;
45 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020046
Dave Rodgman90dfc212023-06-14 17:06:53 +010047 if (strncmp(feature, "MBEDTLS_", 8)) {
48 return -1;
49 }
50
51 feature += 8;
52
Gilles Peskine449bd832023-01-11 14:50:10 +010053 while (*idx != NULL) {
54 if (!strcmp(*idx, feature)) {
55 return 0;
56 }
Paul Bakker0f90d7d2014-04-30 11:49:44 +020057 idx++;
58 }
Gilles Peskine449bd832023-01-11 14:50:10 +010059 return -1;
Paul Bakker0f90d7d2014-04-30 11:49:44 +020060}
61
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020062#endif /* MBEDTLS_VERSION_C */