Line data Source code
1 : /* 2 : * Copyright (C) 2011-2012 Free Software Foundation, Inc. 3 : * 4 : * Author: Nikos Mavrogiannopoulos 5 : * 6 : * This file is part of GnuTLS. 7 : * 8 : * The GnuTLS is free software; you can redistribute it and/or 9 : * modify it under the terms of the GNU Lesser General Public License 10 : * as published by the Free Software Foundation; either version 2.1 of 11 : * the License, or (at your option) any later version. 12 : * 13 : * This library is distributed in the hope that it will be useful, but 14 : * WITHOUT ANY WARRANTY; without even the implied warranty of 15 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 : * Lesser General Public License for more details. 17 : * 18 : * You should have received a copy of the GNU Lesser General Public License 19 : * along with this program. If not, see <https://www.gnu.org/licenses/> 20 : * 21 : */ 22 : 23 : #include "gnutls_int.h" 24 : #include <algorithms.h> 25 : #include "errors.h" 26 : #include <x509/common.h> 27 : #include "c-strcase.h" 28 : 29 : /** 30 : * gnutls_certificate_type_get_name: 31 : * @type: is a certificate type 32 : * 33 : * Convert a #gnutls_certificate_type_t type to a string. 34 : * 35 : * Returns: a string that contains the name of the specified 36 : * certificate type, or %NULL in case of unknown types. 37 : **/ 38 15101 : const char *gnutls_certificate_type_get_name(gnutls_certificate_type_t 39 : type) 40 : { 41 15101 : const char *ret = NULL; 42 : 43 15101 : if (type == GNUTLS_CRT_X509) 44 15092 : ret = "X.509"; 45 15101 : if (type == GNUTLS_CRT_RAWPK) 46 9 : ret = "Raw Public Key"; 47 : 48 15101 : return ret; 49 : } 50 : 51 : /** 52 : * gnutls_certificate_type_get_id: 53 : * @name: is a certificate type name 54 : * 55 : * The names are compared in a case insensitive way. 56 : * 57 : * Returns: a #gnutls_certificate_type_t for the specified in a 58 : * string certificate type, or %GNUTLS_CRT_UNKNOWN on error. 59 : **/ 60 68 : gnutls_certificate_type_t gnutls_certificate_type_get_id(const char *name) 61 : { 62 68 : gnutls_certificate_type_t ret = GNUTLS_CRT_UNKNOWN; 63 : 64 68 : if (c_strcasecmp(name, "X.509") == 0 65 68 : || c_strcasecmp(name, "X509") == 0) 66 : return GNUTLS_CRT_X509; 67 57 : if (c_strcasecmp(name, "RAWPK") == 0) 68 55 : return GNUTLS_CRT_RAWPK; 69 : 70 : return ret; 71 : } 72 : 73 : static const gnutls_certificate_type_t supported_certificate_types[] = { 74 : GNUTLS_CRT_X509, 75 : GNUTLS_CRT_RAWPK, 76 : 0 77 : }; 78 : 79 : /** 80 : * gnutls_certificate_type_list: 81 : * 82 : * Get a list of certificate types. 83 : * 84 : * Returns: a (0)-terminated list of #gnutls_certificate_type_t 85 : * integers indicating the available certificate types. 86 : **/ 87 2 : const gnutls_certificate_type_t *gnutls_certificate_type_list(void) 88 : { 89 2 : return supported_certificate_types; 90 : }