1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-06 05:52:48 -05:00

Utility function ssh_key_clone().

This makes a second independent copy of an existing ssh_key, for
situations where one piece of code is going to want to keep it after
its current owner frees it.

In order to have it work on an arbitrary ssh_key, whether public-only
or a full public+private key pair, I've had to add an ssh_key query
method to ask whether a private key is known. I'm surprised I haven't
found a need for that before! But I suppose in most situations in an
SSH client you statically know which kind of key you're dealing with.
This commit is contained in:
Simon Tatham
2022-04-20 13:51:28 +01:00
parent 180d1b78de
commit c2f1a563a5
6 changed files with 70 additions and 0 deletions

View File

@ -522,6 +522,12 @@ static key_components *rsa2_components(ssh_key *key)
return rsa_components(rsa);
}
static bool rsa2_has_private(ssh_key *key)
{
RSAKey *rsa = container_of(key, RSAKey, sshk);
return rsa->private_exponent != NULL;
}
static void rsa2_public_blob(ssh_key *key, BinarySink *bs)
{
RSAKey *rsa = container_of(key, RSAKey, sshk);
@ -869,6 +875,7 @@ static const struct ssh2_rsa_extra
.public_blob = rsa2_public_blob, \
.private_blob = rsa2_private_blob, \
.openssh_blob = rsa2_openssh_blob, \
.has_private = rsa2_has_private, \
.cache_str = rsa2_cache_str, \
.components = rsa2_components, \
.pubkey_bits = rsa2_pubkey_bits, \