From: Simon Josefsson Date: Mon, 1 Sep 2008 14:18:31 +0000 (+0200) Subject: Add gnutls_pk_list and gnutls_pk_get_id. X-Git-Tag: gnutls_2_5_6~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6db6f35be8efa8d9a2618b72bd4de20edc4bc76a;p=thirdparty%2Fgnutls.git Add gnutls_pk_list and gnutls_pk_get_id. Suggested by Sam Varshavchik . --- diff --git a/NEWS b/NEWS index a06cfdf9fd..709e36829a 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,14 @@ See the end for copying conditions. * Version 2.5.6 (unreleased) +** Add interface to deal with public key algorithms. +The functions are called gnutls_pk_list and gnutls_pk_get_id. +Suggested by Sam Varshavchik . + +** API and ABI modifications: +gnutls_pk_list: ADDED +gnutls_pk_get_id: ADDED + * Version 2.5.5 (released 2008-08-29) ** libgnutls: New API to get a string corresponding to a error symbol. diff --git a/includes/gnutls/gnutls.h.in b/includes/gnutls/gnutls.h.in index 7141c8b064..54310378ec 100644 --- a/includes/gnutls/gnutls.h.in +++ b/includes/gnutls/gnutls.h.in @@ -415,7 +415,7 @@ extern "C" gnutls_kx_algorithm_t gnutls_kx_get_id (const char* name); gnutls_protocol_t gnutls_protocol_get_id (const char* name); gnutls_certificate_type_t gnutls_certificate_type_get_id (const char* name); - + gnutls_pk_algorithm_t gnutls_pk_get_id (const char *name); /* list supported algorithms */ const gnutls_cipher_algorithm_t *gnutls_cipher_list (void); @@ -424,6 +424,7 @@ extern "C" const gnutls_protocol_t *gnutls_protocol_list (void); const gnutls_certificate_type_t *gnutls_certificate_type_list (void); const gnutls_kx_algorithm_t *gnutls_kx_list (void); + const gnutls_pk_algorithm_t *gnutls_pk_list (void); const char *gnutls_cipher_suite_info (size_t i, char *id, gnutls_kx_algorithm_t *kx, diff --git a/lib/gnutls_algorithms.c b/lib/gnutls_algorithms.c index 835cc2242e..67b3549f9e 100644 --- a/lib/gnutls_algorithms.c +++ b/lib/gnutls_algorithms.c @@ -2091,6 +2091,51 @@ gnutls_pk_algorithm_get_name (gnutls_pk_algorithm_t algorithm) return ret; } +/** + * gnutls_pk_list - Get a list of supported public key algorithms + * + * Get a list of supported public key algorithms. + * + * Returns: a zero-terminated list of #gnutls_pk_algorithm_t integers + * indicating the available ciphers. + * + * Since: 2.6.0 + **/ +const gnutls_pk_algorithm_t * +gnutls_pk_list (void) +{ + const static supported_pks[] = { + GNUTLS_PK_RSA, + GNUTLS_PK_DSA + }; + + return supported_pks; +} + +/** + * gnutls_pk_get_id - Get #gnutls_pk_algorithm_t from a string + * @name: is a string containing a public key algorithm name. + * + * Convert a string to a #gnutls_pk_algorithm_t value. The names are + * compared in a case insensitive way. For example, + * gnutls_pk_get_id("RSA") will return %GNUTLS_PK_RSA. + * + * Returns: an #gnutls_pk_algorithm_tid of the specified in a string + * public key algorithm, or %GNUTLS_PK_UNKNOWN on failures. + * + * Since: 2.6.0 + **/ +gnutls_pk_algorithm_t +gnutls_pk_get_id (const char *name) +{ + if (strcasecmp (name, "RSA") == 0) + return GNUTLS_PK_RSA; + else if (strcasecmp (name, "DSA") == 0) + return GNUTLS_PK_DSA; + + return GNUTLS_PK_UNKNOWN; +} + gnutls_pk_algorithm_t _gnutls_x509_oid2pk_algorithm (const char *oid) {