]> the.earth.li Git - onak.git/blob - parsekey.h
Bump debhelper compat level to 13
[onak.git] / parsekey.h
1 /*
2  * parsekey.h - Routines to parse an OpenPGP key.
3  *
4  * Copyright 2002-2004,2007-2008,2011 Jonathan McDowell <noodles@earth.li>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <https://www.gnu.org/licenses/>.
17  */
18
19 #ifndef __PARSEKEY_H__
20 #define __PARSEKEY_H__
21
22 #include "keystructs.h"
23 #include "onak.h"
24
25 /**
26  *      parse_keys - Process a stream of packets for public keys + sigs.
27  *      @packets: The packet list to parse.
28  *      @keys: The returned list of public keys.
29  *
30  *      This function takes an list of OpenPGP packets and attempts to parse it
31  *      into a list of public keys with signatures and subkeys.
32  *
33  *      Returns a count of how many keys we parsed.
34  */
35 int parse_keys(struct openpgp_packet_list *packets,
36                 struct openpgp_publickey **keys);
37
38 /**
39  *      debug_packet - Print debug info about a packet
40  *      @packet: The packet to display.
41  *
42  *      This function takes an OpenPGP packet and displays some information
43  *      about it to stdout. Useful for debugging purposes or curiousity about
44  *      an OpenPGP packet stream.
45  */
46 int debug_packet(struct openpgp_packet *packet);
47
48 /**
49  *      read_openpgp_stream - Reads a stream of OpenPGP packets.
50  *      @getchar_func: The function to get the next character from the stream.
51  *      @ctx: A pointer to the context structure for getchar_func.
52  *      @packets: The outputted list of packets.
53  *      @maxnum: The maximum number of keys to read. 0 means unlimited.
54  *
55  *      This function uses getchar_func to read characters from an OpenPGP
56  *      packet stream and reads the packets into a linked list of packets
57  *      ready for parsing as a public key or whatever. maxnum allows you to
58  *      specify the maximum number of keys to read. Note that if this is used
59  *      then only the public key component of the last key will be returned,
60  *      none of the other packets of the key will be read.
61  */
62 onak_status_t read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
63                                 void *c),
64                                 void *ctx,
65                                 struct openpgp_packet_list **packets,
66                                 int maxnum);
67
68 /**
69  *      write_openpgp_stream - Reads a stream of OpenPGP packets.
70  *      @putchar_func: The function to put the next character to the stream.
71  *      @ctx: A pointer to the context structure for putchar_func.
72  *      @packets: The list of packets.
73  *
74  *      This function uses putchar_func to write characters to an OpenPGP
75  *      packet stream from a linked list of packets.
76  */
77 onak_status_t write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
78                                                 void *c),
79                                 void *ctx,
80                                 struct openpgp_packet_list *packets);
81
82 /**
83  *      flatten_publickey - Convert a publickey to an OpenPGP packet list.
84  *      @key: The public key.
85  *      @packets: The outputted packet list.
86  *      @list_end: The end of the packet list.
87  *
88  *      This function converts public key structure to a linked list of OpenPGP
89  *      packets ready for outputing or storage. If we're not appending to an
90  *      existing list then both packets & list_end will be pointers to NULLs,
91  *      other wise packets should point to the start of the list and list_end
92  *      to the end so we can append to the end.
93  */
94 int flatten_publickey(struct openpgp_publickey *key,
95                         struct openpgp_packet_list **packets,
96                         struct openpgp_packet_list **list_end);
97
98 #endif /* __PARSEKEY_H__ */