From c45633a571bf663bc7f3610fc481acded6acfc19 Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Fri, 19 Feb 2016 14:48:56 +0100 Subject: 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 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. --- g10/packet.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'g10/packet.h') diff --git a/g10/packet.h b/g10/packet.h index 16524f801..dfd3a0008 100644 --- a/g10/packet.h +++ b/g10/packet.h @@ -279,8 +279,12 @@ typedef struct byte pubkey_usage; /* for now only used to pass it to getkey() */ byte req_usage; /* hack to pass a request to getkey() */ u32 has_expired; /* set to the expiration date if expired */ - u32 main_keyid[2]; /* keyid of the primary key */ - u32 keyid[2]; /* calculated by keyid_from_pk() */ + /* keyid of the primary key. Never access this value directly. + Instead, use pk_main_keyid(). */ + u32 main_keyid[2]; + /* keyid of this key. Never access this value directly! Instead, + use pk_keyid(). */ + u32 keyid[2]; prefitem_t *prefs; /* list of preferences (may be NULL) */ struct { -- cgit v1.2.3