diff options
author | Werner Koch <[email protected]> | 2015-05-08 10:05:52 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2015-05-08 10:18:36 +0000 |
commit | b772e459fa91cdc7facd95227ebc0faba20a7003 (patch) | |
tree | 34e36e56de24822af664e4a007154b4b1002a78a /g10/keyedit.c | |
parent | Typo fixes (diff) | |
download | gnupg-b772e459fa91cdc7facd95227ebc0faba20a7003.tar.gz gnupg-b772e459fa91cdc7facd95227ebc0faba20a7003.zip |
gpg: Minor code merging in keyedit.
* g10/keyedit.c (fix_keyblock): Rename to fix_key_signature_order.
(fix_keyblock): New. Call fix_key_signature_order and other fix
functions.
(keyedit_menu): Factor code out to new fix_keyblock.
(keyedit_quick_sign): Ditto. Check for primary fpr before calling
fix_keyblock.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'g10/keyedit.c')
-rw-r--r-- | g10/keyedit.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/g10/keyedit.c b/g10/keyedit.c index 3577bd3cd..804eff19f 100644 --- a/g10/keyedit.c +++ b/g10/keyedit.c @@ -1181,7 +1181,7 @@ change_passphrase (ctrl_t ctrl, kbnode_t keyblock) * Note: This function does not work if there is more than one user ID. */ static int -fix_keyblock (KBNODE keyblock) +fix_key_signature_order (KBNODE keyblock) { KBNODE node, last, subkey; int fixed = 0; @@ -1221,6 +1221,27 @@ fix_keyblock (KBNODE keyblock) } +/* Fix various problems in the keyblock. Returns true if the keyblock + was changed. Note that a pointer to the keyblock must be given and + the function may change it (i.e. replacing the first node). */ +static int +fix_keyblock (kbnode_t *keyblockp) +{ + int changed = 0; + + if (fix_key_signature_order (*keyblockp)) + changed++; + if (collapse_uids (keyblockp)) + changed++; + reorder_keyblock (*keyblockp); + /* If we modified the keyblock, make sure the flags are right. */ + if (changed) + merge_keys_and_selfsig (*keyblockp); + + return changed; +} + + static int parse_sign_type (const char *str, int *localsig, int *nonrevokesig, int *trustsig) @@ -1482,15 +1503,9 @@ keyedit_menu (ctrl_t ctrl, const char *username, strlist_t locusr, log_error (_("key \"%s\" not found: %s\n"), username, gpg_strerror (err)); goto leave; } - if (fix_keyblock (keyblock)) - modified++; - if (collapse_uids (&keyblock)) + + if (fix_keyblock (&keyblock)) modified++; - reorder_keyblock (keyblock); - /* We modified the keyblock, so let's make sure the flags are - right. */ - if (modified) - merge_keys_and_selfsig (keyblock); /* See whether we have a matching secret key. */ if (seckey_check) @@ -2316,11 +2331,6 @@ keyedit_quick_sign (ctrl_t ctrl, const char *fpr, strlist_t uids, log_error (_("key \"%s\" not found: %s\n"), fpr, gpg_strerror (err)); goto leave; } - if (fix_keyblock (keyblock)) - modified++; - if (collapse_uids (&keyblock)) - modified++; - reorder_keyblock (keyblock); /* Check that the primary fingerprint has been given. */ { @@ -2349,9 +2359,8 @@ keyedit_quick_sign (ctrl_t ctrl, const char *fpr, strlist_t uids, } } - /* If we modified the keyblock, make sure the flags are right. */ - if (modified) - merge_keys_and_selfsig (keyblock); + if (fix_keyblock (&keyblock)) + modified++; /* Give some info in verbose. */ if (opt.verbose) |