From: Nikos Mavrogiannopoulos Date: Fri, 30 Dec 2011 22:39:08 +0000 (+0200) Subject: more opencdk simplifications X-Git-Tag: gnutls_3_0_10~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da774307b84256aaf9c7c16b286baadd9c67dd55;p=thirdparty%2Fgnutls.git more opencdk simplifications --- diff --git a/lib/opencdk/kbnode.c b/lib/opencdk/kbnode.c index 8b91e19f6e..3fc767410a 100644 --- a/lib/opencdk/kbnode.c +++ b/lib/opencdk/kbnode.c @@ -1,6 +1,5 @@ /* kbnode.c - keyblock node utility functions - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2007, 2008, 2010 - * Free Software Foundation, Inc. + * Copyright (C) 1998-2003, 2007-2011 Free Software Foundation, Inc. * * Author: Timo Schulz * @@ -396,6 +395,7 @@ cdk_kbnode_get_packet (cdk_kbnode_t node) /** * cdk_kbnode_read_from_mem: * @ret_node: the new key node + * @armor: whether base64 or not * @buf: the buffer which stores the key sequence * @buflen: the length of the buffer * @@ -403,6 +403,7 @@ cdk_kbnode_get_packet (cdk_kbnode_t node) **/ cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, + int armor, const byte * buf, size_t buflen) { cdk_stream_t inp; @@ -418,6 +419,10 @@ cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, rc = cdk_stream_tmp_from_mem (buf, buflen, &inp); if (rc) return rc; + + if (armor) + cdk_stream_set_armor_flag (inp, 0); + rc = cdk_keydb_get_keyblock (inp, ret_node); if (rc) gnutls_assert (); diff --git a/lib/opencdk/opencdk.h b/lib/opencdk/opencdk.h index c15abfbf4f..85531bb7f4 100644 --- a/lib/opencdk/opencdk.h +++ b/lib/opencdk/opencdk.h @@ -852,6 +852,7 @@ extern "C" cdk_kbnode_t cdk_kbnode_new (cdk_packet_t pkt); cdk_error_t cdk_kbnode_read_from_mem (cdk_kbnode_t * ret_node, + int armor, const unsigned char *buf, size_t buflen); cdk_error_t cdk_kbnode_write_to_mem (cdk_kbnode_t node, diff --git a/lib/openpgp/gnutls_openpgp.c b/lib/openpgp/gnutls_openpgp.c index b13281c50f..0ceca8faa5 100644 --- a/lib/openpgp/gnutls_openpgp.c +++ b/lib/openpgp/gnutls_openpgp.c @@ -498,7 +498,7 @@ gnutls_openpgp_count_key_names (const gnutls_datum_t * cert) return 0; } - if (cdk_kbnode_read_from_mem (&knode, cert->data, cert->size)) + if (cdk_kbnode_read_from_mem (&knode, 0, cert->data, cert->size)) { gnutls_assert (); return 0; diff --git a/lib/openpgp/pgp.c b/lib/openpgp/pgp.c index e01264448a..c74dc8d3f5 100644 --- a/lib/openpgp/pgp.c +++ b/lib/openpgp/pgp.c @@ -1,6 +1,5 @@ /* - * Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 - * Free Software Foundation, Inc. + * Copyright (C) 2002-2011 Free Software Foundation, Inc. * * Author: Timo Schulz, Nikos Mavrogiannopoulos * @@ -89,9 +88,8 @@ gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, const gnutls_datum_t * data, gnutls_openpgp_crt_fmt_t format) { - cdk_stream_t inp; cdk_packet_t pkt; - int rc; + int rc, armor; if (data->data == NULL || data->size == 0) { @@ -99,38 +97,15 @@ gnutls_openpgp_crt_import (gnutls_openpgp_crt_t key, return GNUTLS_E_OPENPGP_GETKEY_FAILED; } - if (format == GNUTLS_OPENPGP_FMT_RAW) - { - rc = cdk_kbnode_read_from_mem (&key->knode, data->data, data->size); - if (rc) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } - } - else + if (format == GNUTLS_OPENPGP_FMT_RAW) armor = 0; + else armor = 1; + + rc = cdk_kbnode_read_from_mem (&key->knode, armor, data->data, data->size); + if (rc) { - rc = cdk_stream_tmp_from_mem (data->data, data->size, &inp); - if (rc) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } - rc = cdk_stream_set_armor_flag (inp, 0); - if (!rc) - rc = cdk_keydb_get_keyblock (inp, &key->knode); - cdk_stream_close (inp); - if (rc) - { - if (rc == CDK_Inv_Packet) - rc = GNUTLS_E_OPENPGP_GETKEY_FAILED; - else - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; } /* Test if the import was successful. */ diff --git a/lib/openpgp/privkey.c b/lib/openpgp/privkey.c index f43c53b7ba..81b0e43c56 100644 --- a/lib/openpgp/privkey.c +++ b/lib/openpgp/privkey.c @@ -169,9 +169,8 @@ gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, gnutls_openpgp_crt_fmt_t format, const char *password, unsigned int flags) { - cdk_stream_t inp; cdk_packet_t pkt; - int rc; + int rc, armor; if (data->data == NULL || data->size == 0) { @@ -180,43 +179,15 @@ gnutls_openpgp_privkey_import (gnutls_openpgp_privkey_t key, } if (format == GNUTLS_OPENPGP_FMT_RAW) - { - rc = cdk_kbnode_read_from_mem (&key->knode, data->data, data->size); - if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } - } - else - { - rc = cdk_stream_tmp_from_mem (data->data, data->size, &inp); - if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + armor = 0; + else armor = 1; - rc = cdk_stream_set_armor_flag (inp, 0); - if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - cdk_stream_close (inp); - gnutls_assert (); - return rc; - } - - rc = cdk_keydb_get_keyblock (inp, &key->knode); - cdk_stream_close (inp); - - if (rc != 0) - { - rc = _gnutls_map_cdk_rc (rc); - gnutls_assert (); - return rc; - } + rc = cdk_kbnode_read_from_mem (&key->knode, armor, data->data, data->size); + if (rc != 0) + { + rc = _gnutls_map_cdk_rc (rc); + gnutls_assert (); + return rc; } /* Test if the import was successful. */