From f55cd7de431018bc1799aa9616006569d90f0fcc Mon Sep 17 00:00:00 2001 From: Andreas Schneider Date: Sun, 7 Aug 2011 15:00:35 +0200 Subject: pki: Improve ssh_key_import_private(). --- src/legacy.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/legacy.c') diff --git a/src/legacy.c b/src/legacy.c index 678b065..8655f31 100644 --- a/src/legacy.c +++ b/src/legacy.c @@ -263,6 +263,34 @@ ssh_private_key privatekey_from_base64(ssh_session session, return privkey; } +ssh_private_key privatekey_from_file(ssh_session session, + const char *filename, + int type, + const char *passphrase) { + ssh_key key; + ssh_private_key privkey; + int rc; + + (void) type; /* unused */ + + rc = ssh_key_import_private(session, filename, passphrase, &key); + if (rc == SSH_ERROR) { + return NULL; + } + + privkey = malloc(sizeof(struct ssh_private_key_struct)); + if (privkey == NULL) { + ssh_key_free(key); + return NULL; + } + + privkey->type = key->type; + privkey->dsa_priv = key->dsa; + privkey->rsa_priv = key->rsa; + + return privkey; +} + /**************************************************************************** * SERVER SUPPORT ****************************************************************************/ -- cgit