cscvs to tla changeset 86
[onak.git] / keydb.h
1 /*
2  * keydb.h - Routines to store and fetch keys.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  *
8  * $Id: keydb.h,v 1.9 2003/06/08 21:11:00 noodles Exp $
9  */
10
11 #ifndef __KEYDB_H__
12 #define __KEYDB_H__
13
14 #include <inttypes.h>
15
16 #include "keystructs.h"
17 #include "ll.h"
18
19 /**
20  *      initdb - Initialize the key database.
21  *
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
24  *      for access.
25  */
26 void initdb(void);
27
28 /**
29  *      cleanupdb - De-initialize the key database.
30  *
31  *      This function should be called upon program exit to allow the DB to
32  *      cleanup after itself.
33  */
34 void cleanupdb(void);
35
36 /**
37  *      starttrans - Start a transaction.
38  *
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.
42  */
43 bool starttrans(void);
44
45 /**
46  *      endtrans - End a transaction.
47  *
48  *      Ends a transaction.
49  */
50 void endtrans(void);
51
52 /**
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.
57  *
58  *      This function returns a public key from whatever storage mechanism we
59  *      are using.
60  *
61  *      TODO: What about keyid collisions? Should we use fingerprint instead?
62  */
63 int fetch_key(uint64_t keyid, struct openpgp_publickey **publickey, bool intrans);
64
65 /**
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.
70  *
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
74  *      just being updated.
75  *
76  *      TODO: Do we store multiple keys of the same id? Or only one and replace
77  *      it?
78  */
79 int store_key(struct openpgp_publickey *publickey, bool intrans, bool update);
80
81 /**
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.
85  *
86  *      This function deletes a public key from whatever storage mechanism we
87  *      are using. Returns 0 if the key existed.
88  */
89 int delete_key(uint64_t keyid, bool intrans);
90
91 /**
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.
95  *
96  *      This function searches for the supplied text and returns the keys that
97  *      contain it.
98  */
99 int fetch_key_text(const char *search, struct openpgp_publickey **publickey);
100
101 /**
102  *      keyid2uid - Takes a keyid and returns the primary UID for it.
103  *      @keyid: The keyid to lookup.
104  *
105  *      This function returns a UID for the given key. Returns NULL if the key
106  *      isn't found.
107  */
108 char *keyid2uid(uint64_t keyid);
109
110 /**
111  *      getkeysigs - Gets a linked list of the signatures on a key.
112  *      @keyid: The keyid to get the sigs for.
113  *      @revoked: Is the key revoked?
114  *
115  *      This function gets the list of signatures on a key. Used for key 
116  *      indexing and doing stats bits. If revoked is non-NULL then if the key
117  *      is revoked it's set to true.
118  */
119 struct ll *getkeysigs(uint64_t keyid, bool *revoked);
120
121 /**
122  *      cached_getkeysigs - Gets the signatures on a key.
123  *      @keyid: The key we want the signatures for.
124  *      
125  *      This function gets the signatures on a key. It's the same as the
126  *      getkeysigs function above except we use the hash module to cache the
127  */
128 struct ll *cached_getkeysigs(uint64_t keyid);
129
130 /**
131  *      getfullkeyid - Maps a 32bit key id to a 64bit one.
132  *      @keyid: The 32bit keyid.
133  *
134  *      This function maps a 32bit key id to the full 64bit one. It returns the
135  *      full keyid. If the key isn't found a keyid of 0 is returned.
136  */
137 uint64_t getfullkeyid(uint64_t keyid);
138
139 /**
140  *      dumpdb - dump the key database
141  *      @filenamebase: The base filename to use for the dump.
142  *
143  *      Dumps the database into one or more files, which contain pure OpenPGP
144  *      that can be reimported into onak or gpg. filenamebase provides a base
145  *      file name for the dump; several files may be created, all of which will
146  *      begin with this string and then have a unique number and a .pgp
147  *      extension.
148  */
149 int dumpdb(char *filenamebase);
150
151 #endif /* __KEYDB_H__ */