summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@g10code.com>2016-11-21 16:19:32 +0100
committerNeal H. Walfield <neal@g10code.com>2016-11-21 16:39:53 +0100
commit91a0483c5db8ee4510981448a705981ee1cce199 (patch)
tree5583a2601a30186c2d9135cf5c82b33204577537
parentbuild: Add repo-only maintainer script append-signature.sh. (diff)
downloadgnupg2-91a0483c5db8ee4510981448a705981ee1cce199.tar.xz
gnupg2-91a0483c5db8ee4510981448a705981ee1cce199.zip
g10: Add a convenience function for checking if a key is a primary key
* g10/keydb.h (pk_is_primary): New function. * g10/tofu.c (get_trust): Use it. (tofu_register_signature): Likewise. (tofu_register_encryption): Likewise. (tofu_set_policy): Likewise. (tofu_get_policy): Likewise. Signed-off-by: Neal H. Walfield <neal@g10code.com>
-rw-r--r--g10/keydb.h7
-rw-r--r--g10/tofu.c13
2 files changed, 13 insertions, 7 deletions
diff --git a/g10/keydb.h b/g10/keydb.h
index 815b17ee8..e4fbe274f 100644
--- a/g10/keydb.h
+++ b/g10/keydb.h
@@ -433,6 +433,13 @@ keyid_cmp (const u32 *a, const u32 *b)
return 0;
}
+/* Return whether PK is a primary key. */
+static int GPGRT_ATTR_UNUSED
+pk_is_primary (PKT_public_key *pk)
+{
+ return keyid_cmp (pk_keyid (pk), pk_main_keyid (pk)) == 0;
+}
+
/* Copy the keyid in SRC to DEST and return DEST. */
u32 *keyid_copy (u32 *dest, const u32 *src);
diff --git a/g10/tofu.c b/g10/tofu.c
index 2c9d17cda..05d171d58 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -2186,7 +2186,7 @@ get_trust (ctrl_t ctrl, PKT_public_key *pk,
if (opt.batch)
may_ask = 0;
- log_assert (keyid_cmp (pk_keyid (pk), pk_main_keyid (pk)) == 0);
+ log_assert (pk_is_primary (pk));
/* Make sure _tofu_GET_TRUST_ERROR isn't equal to any of the trust
levels. */
@@ -3009,7 +3009,7 @@ tofu_register_signature (ctrl_t ctrl,
if (rc)
return rc;
- log_assert (keyid_cmp (pk_keyid (pk), pk_main_keyid (pk)) == 0);
+ log_assert (pk_is_primary (pk));
sig_digest = make_radix64_string (sig_digest_bin, sig_digest_bin_len);
fingerprint = hexfingerprint (pk, NULL, 0);
@@ -3155,13 +3155,13 @@ tofu_register_encryption (ctrl_t ctrl,
}
if (/* We need the key block to find the primary key. */
- keyid_cmp (pk_keyid (pk), pk_main_keyid (pk)) != 0
+ ! pk_is_primary (pk)
/* We need the key block to find all user ids. */
|| ! user_id_list)
kb = get_pubkeyblock (pk->keyid);
/* Make sure PK is a primary key. */
- if (keyid_cmp (pk_keyid (pk), pk_main_keyid (pk)) != 0)
+ if (! pk_is_primary (pk))
pk = kb->pkt->pkt.public_key;
if (! user_id_list)
@@ -3485,7 +3485,7 @@ tofu_set_policy (ctrl_t ctrl, kbnode_t kb, enum tofu_policy policy)
if (DBG_TRUST)
log_debug ("Setting TOFU policy for %s to %s\n",
keystr (pk->keyid), tofu_policy_str (policy));
- if (keyid_cmp (pk_main_keyid (pk), pk_keyid (pk)) != 0)
+ if (! pk_is_primary (pk))
log_bug ("%s: Passed a subkey, but expecting a primary key.\n", __func__);
fingerprint = hexfingerprint (pk, NULL, 0);
@@ -3563,8 +3563,7 @@ tofu_get_policy (ctrl_t ctrl, PKT_public_key *pk, PKT_user_id *user_id,
char *email;
/* Make sure PK is a primary key. */
- log_assert (pk->main_keyid[0] == pk->keyid[0]
- && pk->main_keyid[1] == pk->keyid[1]);
+ log_assert (pk_is_primary (pk));
dbs = opendbs (ctrl);
if (! dbs)