[Pkg-gnupg-commit] [gnupg2] 06/180: g10: Add a convenience function for checking if a key is a primary key
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Sat Dec 24 22:29:02 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit 91a0483c5db8ee4510981448a705981ee1cce199
Author: Neal H. Walfield <neal at g10code.com>
Date: Mon Nov 21 16:19:32 2016 +0100
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 at g10code.com>
---
g10/keydb.h | 7 +++++++
g10/tofu.c | 13 ++++++-------
2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/g10/keydb.h b/g10/keydb.h
index 815b17e..e4fbe27 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 2c9d17c..05d171d 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)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list