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.
22 #include "keystructs.h"
28 * keyid2uid - Takes a keyid and returns the primary UID for it.
29 * @keyid: The keyid to lookup.
31 char *keyid2uid(uint64_t keyid)
33 struct openpgp_publickey *publickey = NULL;
34 struct openpgp_signedpacket_list *curuid = NULL;
35 static char buf[1024];
38 if (fetch_key(keyid, &publickey, false) && publickey != NULL) {
39 curuid = publickey->uids;
40 while (curuid != NULL && buf[0] == 0) {
41 if (curuid->packet->tag == 13) {
42 snprintf(buf, 1023, "%.*s",
43 (int) curuid->packet->length,
44 curuid->packet->data);
46 curuid = curuid -> next;
48 free_publickey(publickey);
59 #ifdef NEED_GETKEYSIGS
61 * getkeysigs - Gets a linked list of the signatures on a key.
62 * @keyid: The keyid to get the sigs for.
64 * This function gets the list of signatures on a key. Used for key
65 * indexing and doing stats bits.
67 struct ll *getkeysigs(uint64_t keyid)
69 struct ll *sigs = NULL;
70 struct openpgp_signedpacket_list *uids = NULL;
71 struct openpgp_publickey *publickey = NULL;
73 fetch_key(keyid, &publickey, false);
75 if (publickey != NULL) {
76 for (uids = publickey->uids; uids != NULL; uids = uids->next) {
77 sigs = keysigs(sigs, uids->sigs);
79 free_publickey(publickey);
86 #ifdef NEED_GETFULLKEYID
88 * getfullkeyid - Maps a 32bit key id to a 64bit one.
89 * @keyid: The 32bit keyid.
91 * This function maps a 32bit key id to the full 64bit one. It returns the
94 uint64_t getfullkeyid(uint64_t keyid)
96 struct openpgp_publickey *publickey = NULL;
98 if (keyid < 0x100000000) {
99 fetch_key(keyid, &publickey, false);
100 keyid = get_keyid(publickey);
101 free_publickey(publickey);