diff options
author | Neal H. Walfield <[email protected]> | 2016-02-19 13:48:56 +0000 |
---|---|---|
committer | Neal H. Walfield <[email protected]> | 2016-02-19 15:13:00 +0000 |
commit | c45633a571bf663bc7f3610fc481acded6acfc19 (patch) | |
tree | 4f018128b3528d725717bdcf1102dc6d7fb9d236 /g10/keyid.c | |
parent | gpgparsemail: Allow weirdly-mixed pkcs7 signatures. (diff) | |
download | gnupg-c45633a571bf663bc7f3610fc481acded6acfc19.tar.gz gnupg-c45633a571bf663bc7f3610fc481acded6acfc19.zip |
gpg: Add accessor & utility functions for pk->keyid and pk->main_keyid.
* g10/keydb.h (keyid_cmp): New function.
* g10/keyid.c (pk_keyid): New function.
(pk_main_keyid): New function.
(keyid_copy): New function.
(pk_keyid_str): New function.
* g10/packet.h (PKT_public_key): Update comments for main_keyid and
keyid.
--
Signed-off-by: Neal H. Walfield <[email protected]>
Before accessing pk->keyid, it is necessary to call keyid_from_pk (pk,
NULL) to ensure that pk->keyid is valid. Because it is easy to forget
to do this, these accessor functions take care of it.
Diffstat (limited to 'g10/keyid.c')
-rw-r--r-- | g10/keyid.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/g10/keyid.c b/g10/keyid.c index 49eb5f6d5..f2a5e0357 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -2,6 +2,7 @@ * Copyright (C) 1998, 1999, 2000, 2001, 2003, * 2004, 2006, 2010 Free Software Foundation, Inc. * Copyright (C) 2014 Werner Koch + * Copyright (C) 2016 g10 Code GmbH * * This file is part of GnuPG. * @@ -274,6 +275,52 @@ v3_keyid (gcry_mpi_t a, u32 *ki) } +/* Return PK's keyid. The memory is owned by PK. */ +u32 * +pk_keyid (PKT_public_key *pk) +{ + keyid_from_pk (pk, NULL); + + /* Uncomment this for help tracking down bugs related to keyid or + main_keyid not being set correctly. */ +#if 0 + if (! (pk->main_keyid[0] || pk->main_keyid[1])) + log_bug ("pk->main_keyid not set!\n"); + if (keyid_cmp (pk->keyid, pk->main_keyid) == 0 + && ! pk->flags.primary) + log_bug ("keyid and main_keyid are the same, but primary flag not set!\n"); + if (keyid_cmp (pk->keyid, pk->main_keyid) != 0 + && pk->flags.primary) + log_bug ("keyid and main_keyid are different, but primary flag set!\n"); +#endif + + return pk->keyid; +} + +/* Return the keyid of the primary key associated with PK. The memory + is owned by PK. */ +u32 * +pk_main_keyid (PKT_public_key *pk) +{ + /* Uncomment this for help tracking down bugs related to keyid or + main_keyid not being set correctly. */ +#if 0 + if (! (pk->main_keyid[0] || pk->main_keyid[1])) + log_bug ("pk->main_keyid not set!\n"); +#endif + + return pk->main_keyid; +} + +/* Copy the keyid in SRC to DEST and return DEST. */ +u32 * +keyid_copy (u32 *dest, const u32 *src) +{ + dest[0] = src[0]; + dest[1] = src[1]; + return dest; +} + char * format_keyid (u32 *keyid, int format, char *buffer, int len) { @@ -396,6 +443,14 @@ keystr_from_pk_with_sub (PKT_public_key *main_pk, PKT_public_key *sub_pk) } +/* Return PK's key id as a string using the default format. PK owns + the storage. */ +const char * +pk_keyid_str (PKT_public_key *pk) +{ + return keystr (pk_keyid (pk)); +} + const char * keystr_from_desc(KEYDB_SEARCH_DESC *desc) |