]> the.earth.li Git - onak.git/blob - keystructs.h
Use common function for command sending in keyd client code
[onak.git] / keystructs.h
1 /**
2  * @file keystructs.h
3  * @brief Structures for OpenPGP keys
4  *
5  * Copyright 2002 Jonathan McDowell <noodles@earth.li>
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the Free
9  * Software Foundation; version 2 of the License.
10  *
11  * This program is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14  * more details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program; if not, write to the Free Software Foundation, Inc., 51
18  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef __KEYSTRUCTS_H__
22 #define __KEYSTRUCTS_H__
23
24 #include <inttypes.h>
25 #include <stdbool.h>
26 #include <stdlib.h>
27
28 #include "ll.h"
29
30 /* v3 MD5 fingerprint is 16 characters, v4 SHA-1 fingerprint is 20 */
31 #define MAX_FINGERPRINT_LEN 20
32
33 /**
34  * @brief Stores the fingerprint of an OpenPGP key
35  */
36 struct openpgp_fingerprint {
37         /** Length of fingerprint. 16 bytes for v3, 20 for v4 */
38         size_t length;
39         /** Fingerprint data. Only the first length bytes are valid */
40         uint8_t fp[MAX_FINGERPRINT_LEN];
41 };
42
43 /**
44  * @brief Stores an OpenPGP packet.
45  *
46  * This structure holds any form of OpenPGP packet with minimum common
47  * details decoded out.
48  */
49 struct openpgp_packet {
50         /** The packet tag (i.e. type). */
51         unsigned int tag;
52         /** Indicates if this is a new format packet. */
53         bool newformat;
54         /** The length of the packet. */
55         size_t length;
56         /** The actual packet data. */
57         unsigned char *data;
58 };
59
60 /**
61  * @brief A linked list of OpenPGP packets.
62  *
63  * This structure is used to hold a linked list of packets, for example
64  * all the signatures of a public key's UID.
65  */
66 struct openpgp_packet_list {
67         /** The actual packet structure. */
68         struct openpgp_packet *packet;
69         /** A pointer to the next packet in the list. */
70         struct openpgp_packet_list *next;
71 };
72
73 /**
74  * @brief A packet with signatures.
75  *
76  * This structure holds an OpenPGP packet along with signatures that are
77  * over this packet. It also links to the next signed packet. It's usually
78  * used to hold a UID or subkey with their associated signatures.
79  */
80 struct openpgp_signedpacket_list {
81         /** The OpenPGP packet that's signed. */
82         struct openpgp_packet *packet;
83         /** A linked list of sigs for the packet. */
84         struct openpgp_packet_list *sigs;
85         /** Pointer to the last sig in the sigs linked list */
86         struct openpgp_packet_list *last_sig;
87         /** A pointer to the next packet with signatures. */
88         struct openpgp_signedpacket_list *next;
89 };
90
91 /**
92  * @brief An OpenPGP public key complete with sigs.
93  */
94 struct openpgp_publickey {
95         /** The OpenPGP packet for the public key. */
96         struct openpgp_packet                   *publickey;
97         /** True if the key is revoked. */
98         bool                                     revoked;
99         /** Any signatures directly on the @a publickey packet. */
100         struct openpgp_packet_list              *sigs;
101         /** Pointer to the end of the @a sigs list */
102         struct openpgp_packet_list              *last_sig;
103         /** The list of UIDs with signatures for this key. */
104         struct openpgp_signedpacket_list        *uids;
105         /** Pointer to the end of the @a uids list */
106         struct openpgp_signedpacket_list        *last_uid;
107         /** The list of subkeys with signatures for this key. */
108         struct openpgp_signedpacket_list        *subkeys;
109         /** Pointer to the end of the @a subkey list */
110         struct openpgp_signedpacket_list        *last_subkey;
111         /** The next public key. */
112         struct openpgp_publickey                *next;
113 };
114
115 /**
116  * @brief Holds an SKS key hash (md5 over sorted packet list)
117  */
118 struct skshash {
119         /** The 128 bit MD5 hash of the sorted packet list from the key */
120         uint8_t hash[16];
121 };
122
123 #endif /* __KEYSTRUCTS_H__ */