2 * keydb.h - Routines to store and fetch keys.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2002 Project Purple
8 * $Id: keydb.h,v 1.8 2003/06/07 13:45:34 noodles Exp $
16 #include "keystructs.h"
20 * initdb - Initialize the key database.
22 * This function should be called before any of the other functions in
23 * this file are called in order to allow the DB to be initialized ready
29 * cleanupdb - De-initialize the key database.
31 * This function should be called upon program exit to allow the DB to
32 * cleanup after itself.
37 * starttrans - Start a transaction.
39 * Start a transaction. Intended to be used if we're about to perform many
40 * operations on the database to help speed it all up, or if we want
41 * something to only succeed if all relevant operations are successful.
43 bool starttrans(void);
46 * endtrans - End a transaction.
53 * fetch_key - Given a keyid fetch the key from storage.
54 * @keyid: The keyid to fetch.
55 * @publickey: A pointer to a structure to return the key in.
56 * @intrans: If we're already in a transaction.
58 * This function returns a public key from whatever storage mechanism we
61 * TODO: What about keyid collisions? Should we use fingerprint instead?
63 int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, bool intrans);
66 * store_key - Takes a key and stores it.
67 * @publickey: A pointer to the public key to store.
68 * @intrans: If we're already in a transaction.
69 * @update: If true the key exists and should be updated.
71 * This function stores a public key in whatever storage mechanism we are
72 * using. intrans indicates if we're already in a transaction so don't
73 * need to start one. update indicates if the key already exists and is
76 * TODO: Do we store multiple keys of the same id? Or only one and replace
79 int store_key(struct openpgp_publickey *publickey, bool intrans, bool update);
82 * delete_key - Given a keyid delete the key from storage.
83 * @keyid: The keyid to delete.
84 * @intrans: If we're already in a transaction.
86 * This function deletes a public key from whatever storage mechanism we
87 * are using. Returns 0 if the key existed.
89 int delete_key(uint64_t keyid, bool intrans);
92 * fetch_key_text - Trys to find the keys that contain the supplied text.
93 * @search: The text to search for.
94 * @publickey: A pointer to a structure to return the key in.
96 * This function searches for the supplied text and returns the keys that
99 int fetch_key_text(const char *search, struct openpgp_publickey **publickey);
102 * keyid2uid - Takes a keyid and returns the primary UID for it.
103 * @keyid: The keyid to lookup.
105 * This function returns a UID for the given key. Returns NULL if the key
108 char *keyid2uid(uint64_t keyid);
111 * getkeysigs - Gets a linked list of the signatures on a key.
112 * @keyid: The keyid to get the sigs for.
114 * This function gets the list of signatures on a key. Used for key
115 * indexing and doing stats bits.
117 struct ll *getkeysigs(uint64_t keyid);
120 * cached_getkeysigs - Gets the signatures on a key.
121 * @keyid: The key we want the signatures for.
123 * This function gets the signatures on a key. It's the same as the
124 * getkeysigs function above except we use the hash module to cache the
126 struct ll *cached_getkeysigs(uint64_t keyid);
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);
138 * dumpdb - dump the key database
139 * @filenamebase: The base filename to use for the dump.
141 * Dumps the database into one or more files, which contain pure OpenPGP
142 * that can be reimported into onak or gpg. filenamebase provides a base
143 * file name for the dump; several files may be created, all of which will
144 * begin with this string and then have a unique number and a .pgp
147 int dumpdb(char *filenamebase);
149 #endif /* __KEYDB_H__ */