aboutsummaryrefslogtreecommitdiff
path: root/src/legacy.c
diff options
context:
space:
mode:
authorAndreas Schneider <asn@cryptomilk.org>2011-08-30 11:40:16 +0200
committerAndreas Schneider <asn@cryptomilk.org>2011-08-30 12:15:20 +0200
commit64de14f51e447cc0d25a91c8ebe2a1e2108972ab (patch)
tree23e7049a0c285bdf2cf97868cbbf26155acf6ba7 /src/legacy.c
parentfe246db27d69e6e27ebde35f6e72e41802ce4a26 (diff)
downloadlibssh-64de14f51e447cc0d25a91c8ebe2a1e2108972ab.tar.gz
libssh-64de14f51e447cc0d25a91c8ebe2a1e2108972ab.tar.xz
libssh-64de14f51e447cc0d25a91c8ebe2a1e2108972ab.zip
keys: Move publickey_from_privatekey() to legacy.c.
Diffstat (limited to 'src/legacy.c')
-rw-r--r--src/legacy.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/legacy.c b/src/legacy.c
index d15508c7..56f58370 100644
--- a/src/legacy.c
+++ b/src/legacy.c
@@ -302,7 +302,6 @@ ssh_private_key privatekey_from_file(ssh_session session, const char *filename,
int type, const char *passphrase);
int ssh_publickey_to_file(ssh_session session, const char *file,
ssh_string pubkey, int type);
-ssh_public_key publickey_from_privatekey(ssh_private_key prv);
ssh_string publickey_to_string(ssh_public_key key);
*
*/
@@ -372,6 +371,37 @@ void publickey_free(ssh_public_key key) {
SAFE_FREE(key);
}
+ssh_public_key publickey_from_privatekey(ssh_private_key prv) {
+ struct ssh_public_key_struct *p;
+ ssh_key privkey;
+ ssh_key pubkey;
+ int rc;
+
+ privkey = ssh_key_new();
+ if (privkey == NULL) {
+ return NULL;
+ }
+
+ privkey->type = prv->type;
+ privkey->type_c = ssh_key_type_to_char(privkey->type);
+ privkey->flags = SSH_KEY_FLAG_PRIVATE | SSH_KEY_FLAG_PUBLIC;
+ privkey->dsa = prv->dsa_priv;
+ privkey->rsa = prv->rsa_priv;
+
+ rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey);
+ privkey->dsa = NULL;
+ privkey->rsa = NULL;
+ ssh_key_free(privkey);
+ if (rc < 0) {
+ return NULL;
+ }
+
+ p = ssh_pki_convert_key_to_publickey(pubkey);
+ ssh_key_free(pubkey);
+
+ return p;
+}
+
ssh_private_key privatekey_from_file(ssh_session session,
const char *filename,
int type,