2 * keydb.c - Routines for DB access that just use store/fetch.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
10 * The routines in this file are meant to be used as an initial step when
11 * adding a new db access module. They provide various functions required
12 * of the db access module using only the store and fetch functions. As
13 * they need to parse the actual OpenPGP data to work they are a lot
14 * slower than custom functions however.
19 #include "decodekey.h"
23 #include "keystructs.h"
29 * keyid2uid - Takes a keyid and returns the primary UID for it.
30 * @keyid: The keyid to lookup.
32 char *keyid2uid(uint64_t keyid)
34 struct openpgp_publickey *publickey = NULL;
35 struct openpgp_signedpacket_list *curuid = NULL;
39 if (fetch_key(keyid, &publickey, false) && publickey != NULL) {
40 curuid = publickey->uids;
41 while (curuid != NULL && buf[0] == 0) {
42 if (curuid->packet->tag == 13) {
43 snprintf(buf, 1023, "%.*s",
44 (int) curuid->packet->length,
45 curuid->packet->data);
47 curuid = curuid -> next;
49 free_publickey(publickey);
60 #ifdef NEED_GETKEYSIGS
62 * getkeysigs - Gets a linked list of the signatures on a key.
63 * @keyid: The keyid to get the sigs for.
65 * This function gets the list of signatures on a key. Used for key
66 * indexing and doing stats bits.
68 struct ll *getkeysigs(uint64_t keyid)
70 struct ll *sigs = NULL;
71 struct openpgp_signedpacket_list *uids = NULL;
72 struct openpgp_publickey *publickey = NULL;
74 fetch_key(keyid, &publickey, false);
76 if (publickey != NULL) {
77 for (uids = publickey->uids; uids != NULL; uids = uids->next) {
78 sigs = keysigs(sigs, uids->sigs);
80 free_publickey(publickey);
88 * cached_getkeysigs - Gets the signatures on a key.
89 * @keyid: The key we want the signatures for.
91 * This function gets the signatures on a key. It's the same as the
92 * getkeysigs function above except we use the hash module to cache the
93 * data so if we need it again it's already loaded.
95 struct ll *cached_getkeysigs(uint64_t keyid)
97 struct stats_key *key = NULL;
103 key = findinhash(keyid);
105 key = malloc(sizeof(*key));
111 key->gotsigs = false;
112 key->disabled = false;
115 perror("cached_getkeysigs()");
119 if (key->gotsigs == false) {
120 key->sigs = getkeysigs(key->keyid);
127 #ifdef NEED_GETFULLKEYID
129 * getfullkeyid - Maps a 32bit key id to a 64bit one.
130 * @keyid: The 32bit keyid.
132 * This function maps a 32bit key id to the full 64bit one. It returns the
133 * full keyid. If the key isn't found a keyid of 0 is returned.
135 uint64_t getfullkeyid(uint64_t keyid)
137 struct openpgp_publickey *publickey = NULL;
139 if (keyid < 0x100000000LL) {
140 fetch_key(keyid, &publickey, false);
141 if (publickey != NULL) {
142 keyid = get_keyid(publickey);
143 free_publickey(publickey);