cscvs to tla changeset 99
[onak.git] / parsekey.h
1 /*
2  * parsekey.h - Routines to parse an OpenPGP key.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  *
8  * $Id: parsekey.h,v 1.5 2003/09/30 20:40:11 noodles Exp $
9  */
10
11 #ifndef __PARSEKEY_H__
12 #define __PARSEKEY_H__
13
14 #include "keystructs.h"
15
16 /**
17  *      add_key - Takes a key and adds it to the keyserver.
18  *      @key: The public key to add.
19  *
20  *      This function takes a public key and adds it to the keyserver.
21  *      It first of all sees if we already have the key locally. If we do then
22  *      we retrieve it and merge the two keys. We then store the resulting key
23  *      (or just the original we received if we don't already have it). We then
24  *      send out the appropriate updates to our keyserver peers.
25  */
26 int add_key(struct openpgp_publickey *key);
27
28 /**
29  *      parse_keys - Process a stream of packets for public keys + sigs.
30  *      @packets: The packet list to parse.
31  *      @keys: The returned list of public keys.
32  *
33  *      This function takes an list of OpenPGP packets and attempts to parse it
34  *      into a list of public keys with signatures and subkeys.
35  *
36  *      Returns a count of how many keys we parsed.
37  */
38 int parse_keys(struct openpgp_packet_list *packets,
39                 struct openpgp_publickey **keys);
40
41 /**
42  *      debug_packet - Print debug info about a packet
43  *      @packet: The packet to display.
44  *
45  *      This function takes an OpenPGP packet and displays some information
46  *      about it to stdout. Useful for debugging purposes or curiousity about
47  *      an OpenPGP packet stream.
48  */
49 int debug_packet(struct openpgp_packet *packet);
50
51 /**
52  *      read_openpgp_stream - Reads a stream of OpenPGP packets.
53  *      @getchar_func: The function to get the next character from the stream.
54  *      @ctx: A pointer to the context structure for getchar_func.
55  *      @packets: The outputted list of packets.
56  *      @maxnum: The maximum number of keys to read. 0 means unlimited.
57  *
58  *      This function uses getchar_func to read characters from an OpenPGP
59  *      packet stream and reads the packets into a linked list of packets
60  *      ready for parsing as a public key or whatever. maxnum allows you to
61  *      specify the maximum number of keys to read. Note that if this is used
62  *      then only the public key component of the last key will be returned,
63  *      none of the other packets of the key will be read.
64  */
65 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
66                                 unsigned char *c),
67                                 void *ctx,
68                                 struct openpgp_packet_list **packets,
69                                 int maxnum);
70
71 /**
72  *      write_openpgp_stream - Reads a stream of OpenPGP packets.
73  *      @putchar_func: The function to put the next character to the stream.
74  *      @ctx: A pointer to the context structure for putchar_func.
75  *      @packets: The list of packets.
76  *
77  *      This function uses putchar_func to write characters to an OpenPGP
78  *      packet stream from a linked list of packets.
79  */
80 int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
81                                                 unsigned char *c),
82                                 void *ctx,
83                                 struct openpgp_packet_list *packets);
84
85 /**
86  *      flatten_publickey - Convert a publickey to an OpenPGP packet list.
87  *      @key: The public key.
88  *      @packets: The outputted packet list.
89  *      @list_end: The end of the packet list.
90  *
91  *      This function converts public key structure to a linked list of OpenPGP
92  *      packets ready for outputing or storage. If we're not appending to an
93  *      existing list then both packets & list_end will be pointers to NULLs,
94  *      other wise packets should point to the start of the list and list_end
95  *      to the end so we can append to the end.
96  */
97 int flatten_publickey(struct openpgp_publickey *key,
98                         struct openpgp_packet_list **packets,
99                         struct openpgp_packet_list **list_end);
100
101 #endif /* __PARSEKEY_H__ */