doc updates
[gnutls.git] / lib / algorithms / cert_types.c
blob5fa6b8fb530c420c6125cce9dd1c216b7c222068
1 /*
2 * Copyright (C) 2011-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
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 3 of
11 * the License, or (at your option) any later version.
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.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #include <gnutls_int.h>
24 #include <algorithms.h>
25 #include <gnutls_errors.h>
26 #include <x509/common.h>
28 /**
29 * gnutls_certificate_type_get_name:
30 * @type: is a certificate type
32 * Convert a #gnutls_certificate_type_t type to a string.
34 * Returns: a string that contains the name of the specified
35 * certificate type, or %NULL in case of unknown types.
36 **/
37 const char *
38 gnutls_certificate_type_get_name (gnutls_certificate_type_t type)
40 const char *ret = NULL;
42 if (type == GNUTLS_CRT_X509)
43 ret = "X.509";
44 if (type == GNUTLS_CRT_OPENPGP)
45 ret = "OPENPGP";
47 return ret;
50 /**
51 * gnutls_certificate_type_get_id:
52 * @name: is a certificate type name
54 * The names are compared in a case insensitive way.
56 * Returns: a #gnutls_certificate_type_t for the specified in a
57 * string certificate type, or %GNUTLS_CRT_UNKNOWN on error.
58 **/
59 gnutls_certificate_type_t
60 gnutls_certificate_type_get_id (const char *name)
62 gnutls_certificate_type_t ret = GNUTLS_CRT_UNKNOWN;
64 if (strcasecmp (name, "X.509") == 0 || strcasecmp (name, "X509") == 0)
65 return GNUTLS_CRT_X509;
66 if (strcasecmp (name, "OPENPGP") == 0)
67 return GNUTLS_CRT_OPENPGP;
69 return ret;
72 static const gnutls_certificate_type_t supported_certificate_types[] = {
73 GNUTLS_CRT_X509,
74 GNUTLS_CRT_OPENPGP,
78 /**
79 * gnutls_certificate_type_list:
81 * Get a list of certificate types.
83 * Returns: a (0)-terminated list of #gnutls_certificate_type_t
84 * integers indicating the available certificate types.
85 **/
86 const gnutls_certificate_type_t *
87 gnutls_certificate_type_list (void)
89 return supported_certificate_types;