cscvs to tla changeset 107
[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.6 2003/10/04 10:21:40 noodles Exp $
9  */
10
11 #ifndef __PARSEKEY_H__
12 #define __PARSEKEY_H__
13
14 #include "keystructs.h"
15
16 /**
17  *      parse_keys - Process a stream of packets for public keys + sigs.
18  *      @packets: The packet list to parse.
19  *      @keys: The returned list of public keys.
20  *
21  *      This function takes an list of OpenPGP packets and attempts to parse it
22  *      into a list of public keys with signatures and subkeys.
23  *
24  *      Returns a count of how many keys we parsed.
25  */
26 int parse_keys(struct openpgp_packet_list *packets,
27                 struct openpgp_publickey **keys);
28
29 /**
30  *      debug_packet - Print debug info about a packet
31  *      @packet: The packet to display.
32  *
33  *      This function takes an OpenPGP packet and displays some information
34  *      about it to stdout. Useful for debugging purposes or curiousity about
35  *      an OpenPGP packet stream.
36  */
37 int debug_packet(struct openpgp_packet *packet);
38
39 /**
40  *      read_openpgp_stream - Reads a stream of OpenPGP packets.
41  *      @getchar_func: The function to get the next character from the stream.
42  *      @ctx: A pointer to the context structure for getchar_func.
43  *      @packets: The outputted list of packets.
44  *      @maxnum: The maximum number of keys to read. 0 means unlimited.
45  *
46  *      This function uses getchar_func to read characters from an OpenPGP
47  *      packet stream and reads the packets into a linked list of packets
48  *      ready for parsing as a public key or whatever. maxnum allows you to
49  *      specify the maximum number of keys to read. Note that if this is used
50  *      then only the public key component of the last key will be returned,
51  *      none of the other packets of the key will be read.
52  */
53 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
54                                 unsigned char *c),
55                                 void *ctx,
56                                 struct openpgp_packet_list **packets,
57                                 int maxnum);
58
59 /**
60  *      write_openpgp_stream - Reads a stream of OpenPGP packets.
61  *      @putchar_func: The function to put the next character to the stream.
62  *      @ctx: A pointer to the context structure for putchar_func.
63  *      @packets: The list of packets.
64  *
65  *      This function uses putchar_func to write characters to an OpenPGP
66  *      packet stream from a linked list of packets.
67  */
68 int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
69                                                 unsigned char *c),
70                                 void *ctx,
71                                 struct openpgp_packet_list *packets);
72
73 /**
74  *      flatten_publickey - Convert a publickey to an OpenPGP packet list.
75  *      @key: The public key.
76  *      @packets: The outputted packet list.
77  *      @list_end: The end of the packet list.
78  *
79  *      This function converts public key structure to a linked list of OpenPGP
80  *      packets ready for outputing or storage. If we're not appending to an
81  *      existing list then both packets & list_end will be pointers to NULLs,
82  *      other wise packets should point to the start of the list and list_end
83  *      to the end so we can append to the end.
84  */
85 int flatten_publickey(struct openpgp_publickey *key,
86                         struct openpgp_packet_list **packets,
87                         struct openpgp_packet_list **list_end);
88
89 #endif /* __PARSEKEY_H__ */