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"
27 * keyid2uid - Takes a keyid and returns the primary UID for it.
28 * @keyid: The keyid to lookup.
30 char *keyid2uid(uint64_t keyid)
32 struct openpgp_publickey *publickey = NULL;
33 struct openpgp_signedpacket_list *curuid = NULL;
34 static char buf[1024];
37 if (fetch_key(keyid, &publickey) && publickey != NULL) {
38 curuid = publickey->uids;
39 while (curuid != NULL && buf[0] == 0) {
40 if (curuid->packet->tag == 13) {
41 snprintf(buf, 1023, "%.*s",
42 (int) curuid->packet->length,
43 curuid->packet->data);
45 curuid = curuid -> next;
47 free_publickey(publickey);
58 * getkeysigs - Gets a linked list of the signatures on a key.
59 * @keyid: The keyid to get the sigs for.
61 * This function gets the list of signatures on a key. Used for key
62 * indexing and doing stats bits.
64 struct ll *getkeysigs(uint64_t keyid)
66 struct ll *sigs = NULL;
67 struct openpgp_signedpacket_list *uids = NULL;
68 struct openpgp_publickey *publickey = NULL;
70 fetch_key(keyid, &publickey);
72 if (publickey != NULL) {
73 for (uids = publickey->uids; uids != NULL; uids = uids->next) {
74 sigs = keysigs(sigs, uids->sigs);
76 free_publickey(publickey);