From 1a0fbedc2e7bc688ce380bbb465a5e1710355666 Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Tue, 16 Aug 2011 22:15:05 +0200 Subject: [PATCH] pki: Fix and rename ssh_pki_publickey_to_base64(). Rename it to ssh_pki_export_publickey_base64(). --- include/libssh/libssh.h | 5 ++--- src/pki.c | 14 +++++++------- tests/unittests/torture_pki.c | 10 ++++------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h index 80121b7f..12c52cb1 100644 --- a/include/libssh/libssh.h +++ b/include/libssh/libssh.h @@ -457,9 +457,8 @@ LIBSSH_API int ssh_pki_import_pubkey_base64(const char *b64_key, ssh_key *pkey); LIBSSH_API int ssh_pki_import_pubkey_file(const char *filename, ssh_key *pkey); -LIBSSH_API int ssh_pki_publickey_to_base64(const ssh_key key, - unsigned char **b64_key, - enum ssh_keytypes_e *ptype); +LIBSSH_API int ssh_pki_export_publickey_base64(const ssh_key key, + char **b64_key); LIBSSH_API int ssh_userauth_pki_pubkey(ssh_session session, const char *username, ssh_string publickey, ssh_key privatekey); diff --git a/src/pki.c b/src/pki.c index 0fc36d05..867d1243 100644 --- a/src/pki.c +++ b/src/pki.c @@ -725,19 +725,17 @@ ssh_string ssh_pki_publickey_to_blob(const ssh_key key) * * @param[out] b64_key A pointer to store the base64 hased key. * - * @param[out] ptype The type of the key. - * * @return SSH_OK on success, SSH_ERROR on error. * * @see ssh_string_free_char() */ -int ssh_pki_publickey_to_base64(const ssh_key key, unsigned char **b64_key, - enum ssh_keytypes_e *ptype) +int ssh_pki_export_publickey_base64(const ssh_key key, + char **b64_key) { ssh_string key_str; unsigned char *b64; - if (key == NULL || b64_key == NULL || ptype == NULL) { + if (key == NULL || b64_key == NULL) { return SSH_ERROR; } @@ -748,9 +746,11 @@ int ssh_pki_publickey_to_base64(const ssh_key key, unsigned char **b64_key, b64 = bin_to_base64(ssh_string_data(key_str), ssh_string_len(key_str)); ssh_string_free(key_str); + if (b64 == NULL) { + return SSH_ERROR; + } - *ptype = key->type; - *b64_key = b64; + *b64_key = (char *)b64; return SSH_OK; } diff --git a/tests/unittests/torture_pki.c b/tests/unittests/torture_pki.c index 8a709927..643fc120 100644 --- a/tests/unittests/torture_pki.c +++ b/tests/unittests/torture_pki.c @@ -264,9 +264,8 @@ static void torture_pki_publickey_dsa_base64(void **state) { ssh_session session = *state; enum ssh_keytypes_e type; - char *key_buf, *p; + char *b64_key, *key_buf, *p; const char *q; - unsigned char *b64_key; ssh_key key; int rc; @@ -287,7 +286,7 @@ static void torture_pki_publickey_dsa_base64(void **state) rc = ssh_pki_import_pubkey_base64(q, type, &key); assert_true(rc == 0); - rc = ssh_pki_publickey_to_base64(key, &b64_key, &type); + rc = ssh_pki_export_publickey_base64(key, &b64_key); assert_true(rc == 0); assert_string_equal(q, b64_key); @@ -301,9 +300,8 @@ static void torture_pki_publickey_rsa_base64(void **state) { ssh_session session = *state; enum ssh_keytypes_e type; - char *key_buf, *p; + char *b64_key, *key_buf, *p; const char *q; - unsigned char *b64_key; ssh_key key; int rc; @@ -325,7 +323,7 @@ static void torture_pki_publickey_rsa_base64(void **state) rc = ssh_pki_import_pubkey_base64(q, type, &key); assert_true(rc == 0); - rc = ssh_pki_publickey_to_base64(key, &b64_key, &type); + rc = ssh_pki_export_publickey_base64(key, &b64_key); assert_true(rc == 0); assert_string_equal(q, b64_key);