mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-09 12:54:23 +01:00
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>
This commit is contained in:
parent
362afb4f60
commit
91a0483c5d
@ -433,6 +433,13 @@ keyid_cmp (const u32 *a, const u32 *b)
|
|||||||
return 0;
|
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. */
|
/* Copy the keyid in SRC to DEST and return DEST. */
|
||||||
u32 *keyid_copy (u32 *dest, const u32 *src);
|
u32 *keyid_copy (u32 *dest, const u32 *src);
|
||||||
|
|
||||||
|
13
g10/tofu.c
13
g10/tofu.c
@ -2186,7 +2186,7 @@ get_trust (ctrl_t ctrl, PKT_public_key *pk,
|
|||||||
if (opt.batch)
|
if (opt.batch)
|
||||||
may_ask = 0;
|
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
|
/* Make sure _tofu_GET_TRUST_ERROR isn't equal to any of the trust
|
||||||
levels. */
|
levels. */
|
||||||
@ -3009,7 +3009,7 @@ tofu_register_signature (ctrl_t ctrl,
|
|||||||
if (rc)
|
if (rc)
|
||||||
return 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);
|
sig_digest = make_radix64_string (sig_digest_bin, sig_digest_bin_len);
|
||||||
fingerprint = hexfingerprint (pk, NULL, 0);
|
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. */
|
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. */
|
/* We need the key block to find all user ids. */
|
||||||
|| ! user_id_list)
|
|| ! user_id_list)
|
||||||
kb = get_pubkeyblock (pk->keyid);
|
kb = get_pubkeyblock (pk->keyid);
|
||||||
|
|
||||||
/* Make sure PK is a primary key. */
|
/* 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;
|
pk = kb->pkt->pkt.public_key;
|
||||||
|
|
||||||
if (! user_id_list)
|
if (! user_id_list)
|
||||||
@ -3485,7 +3485,7 @@ tofu_set_policy (ctrl_t ctrl, kbnode_t kb, enum tofu_policy policy)
|
|||||||
if (DBG_TRUST)
|
if (DBG_TRUST)
|
||||||
log_debug ("Setting TOFU policy for %s to %s\n",
|
log_debug ("Setting TOFU policy for %s to %s\n",
|
||||||
keystr (pk->keyid), tofu_policy_str (policy));
|
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__);
|
log_bug ("%s: Passed a subkey, but expecting a primary key.\n", __func__);
|
||||||
|
|
||||||
fingerprint = hexfingerprint (pk, NULL, 0);
|
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;
|
char *email;
|
||||||
|
|
||||||
/* Make sure PK is a primary key. */
|
/* Make sure PK is a primary key. */
|
||||||
log_assert (pk->main_keyid[0] == pk->keyid[0]
|
log_assert (pk_is_primary (pk));
|
||||||
&& pk->main_keyid[1] == pk->keyid[1]);
|
|
||||||
|
|
||||||
dbs = opendbs (ctrl);
|
dbs = opendbs (ctrl);
|
||||||
if (! dbs)
|
if (! dbs)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user