mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 19:42:48 -05:00
Reorganise ssh_keyalg and use it as a vtable.
After Pavel Kryukov pointed out that I have to put _something_ in the 'ssh_key' structure, I thought of an actually useful thing to put there: why not make it store a pointer to the ssh_keyalg structure? Then ssh_key becomes a classoid - or perhaps 'traitoid' is a closer analogy - in the same style as Socket and Plug. And just like Socket and Plug, I've also arranged a system of wrapper macros that avoid the need to mention the 'object' whose method you're invoking twice at each call site. The new vtable pointer directly replaces an existing field of struct ec_key (which was usable by several different ssh_keyalgs, so it already had to store a pointer to the currently active one), and also replaces the 'alg' field of the ssh2_userkey structure that wraps up a cryptographic key with its comment field. I've also taken the opportunity to clean things up a bit in general: most of the methods now have new and clearer names (e.g. you'd never know that 'newkey' made a public-only key while 'createkey' made a public+private key pair unless you went and looked it up, but now they're called 'new_pub' and 'new_priv' you might be in with a chance), and I've completely removed the openssh_private_npieces field after realising that it was duplicating information that is actually _more_ conveniently obtained by calling the new_priv_openssh method (formerly openssh_createkey) and throwing away the result.
This commit is contained in:
@ -769,7 +769,7 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
|
||||
|
||||
savecomment = state->ssh2key.comment;
|
||||
state->ssh2key.comment = NULL;
|
||||
fp = ssh2_fingerprint(state->ssh2key.alg, state->ssh2key.data);
|
||||
fp = ssh2_fingerprint(state->ssh2key.key);
|
||||
state->ssh2key.comment = savecomment;
|
||||
|
||||
SetDlgItemText(hwnd, IDC_FINGERPRINT, fp);
|
||||
@ -1321,8 +1321,8 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
} else {
|
||||
if (state->ssh2) {
|
||||
strbuf *blob = strbuf_new();
|
||||
state->ssh2key.alg->public_blob(
|
||||
state->ssh2key.data, BinarySink_UPCAST(blob));
|
||||
ssh_key_public_blob(
|
||||
state->ssh2key.key, BinarySink_UPCAST(blob));
|
||||
ssh2_write_pubkey(fp, state->ssh2key.comment,
|
||||
blob->u, blob->len,
|
||||
SSH_KEYTYPE_SSH2_PUBLIC_RFC4716);
|
||||
@ -1365,17 +1365,13 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETPOS, PROGRESSRANGE, 0);
|
||||
if (state->ssh2) {
|
||||
if (state->keytype == DSA) {
|
||||
state->ssh2key.data = &state->dsskey.sshk;
|
||||
state->ssh2key.alg = &ssh_dss;
|
||||
state->ssh2key.key = &state->dsskey.sshk;
|
||||
} else if (state->keytype == ECDSA) {
|
||||
state->ssh2key.data = &state->eckey.sshk;
|
||||
state->ssh2key.alg = state->eckey.signalg;
|
||||
state->ssh2key.key = &state->eckey.sshk;
|
||||
} else if (state->keytype == ED25519) {
|
||||
state->ssh2key.data = &state->eckey.sshk;
|
||||
state->ssh2key.alg = &ssh_ecdsa_ed25519;
|
||||
state->ssh2key.key = &state->eckey.sshk;
|
||||
} else {
|
||||
state->ssh2key.data = &state->key.sshk;
|
||||
state->ssh2key.alg = &ssh_rsa;
|
||||
state->ssh2key.key = &state->key.sshk;
|
||||
}
|
||||
state->commentptr = &state->ssh2key.comment;
|
||||
} else {
|
||||
@ -1423,7 +1419,7 @@ static INT_PTR CALLBACK MainDlgProc(HWND hwnd, UINT msg,
|
||||
savecomment = *state->commentptr;
|
||||
*state->commentptr = NULL;
|
||||
if (state->ssh2)
|
||||
fp = ssh2_fingerprint(state->ssh2key.alg, state->ssh2key.data);
|
||||
fp = ssh2_fingerprint(state->ssh2key.key);
|
||||
else
|
||||
fp = rsa_ssh1_fingerprint(&state->key);
|
||||
SetDlgItemText(hwnd, IDC_FINGERPRINT, fp);
|
||||
|
@ -339,7 +339,7 @@ void keylist_update(void)
|
||||
* stop and leave out a tab character. Urgh.
|
||||
*/
|
||||
|
||||
p = ssh2_fingerprint(skey->alg, skey->data);
|
||||
p = ssh2_fingerprint(skey->key);
|
||||
listentry = dupprintf("%s\t%s", p, skey->comment);
|
||||
sfree(p);
|
||||
|
||||
@ -350,7 +350,8 @@ void keylist_update(void)
|
||||
break;
|
||||
listentry[pos++] = '\t';
|
||||
}
|
||||
if (skey->alg != &ssh_dss && skey->alg != &ssh_rsa) {
|
||||
if (ssh_key_alg(skey->key) != &ssh_dss &&
|
||||
ssh_key_alg(skey->key) != &ssh_rsa) {
|
||||
/*
|
||||
* Remove the bit-count field, which is between the
|
||||
* first and second \t.
|
||||
@ -647,7 +648,7 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
|
||||
|
||||
if (selectedArray[itemNum] == rCount + i) {
|
||||
pageant_delete_ssh2_key(skey);
|
||||
skey->alg->freekey(skey->data);
|
||||
ssh_key_free(skey->key);
|
||||
sfree(skey);
|
||||
itemNum--;
|
||||
}
|
||||
|
Reference in New Issue
Block a user