]> the.earth.li Git - onak.git/blob - keystructs.h
Fix handling of other signature requirement
[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, see <https://www.gnu.org/licenses/>.
18  */
19
20 #ifndef __KEYSTRUCTS_H__
21 #define __KEYSTRUCTS_H__
22
23 #include <inttypes.h>
24 #include <stdbool.h>
25 #include <stdlib.h>
26
27 #include "ll.h"
28
29 /*
30  * Fingerprint lengths
31  *
32  * v3 MD5 fingerprint is 16 bytes
33  * v4 SHA-1 fingerprint is 20
34  * v5 SHA2-256 fingerprint is 32
35  */
36 #define FINGERPRINT_V3_LEN      16
37 #define FINGERPRINT_V4_LEN      20
38 #define FINGERPRINT_V5_LEN      32
39 #define MAX_FINGERPRINT_LEN     32
40
41 /**
42  * @brief Stores the fingerprint of an OpenPGP key
43  */
44 struct openpgp_fingerprint {
45         /** Length of fingerprint. 16 bytes for v3, 20 for v4 */
46         size_t length;
47         /** Fingerprint data. Only the first length bytes are valid */
48         uint8_t fp[MAX_FINGERPRINT_LEN];
49 };
50
51 /**
52  * @brief Stores an OpenPGP packet.
53  *
54  * This structure holds any form of OpenPGP packet with minimum common
55  * details decoded out.
56  */
57 struct openpgp_packet {
58         /** The packet tag (i.e. type). */
59         unsigned int tag;
60         /** Indicates if this is a new format packet. */
61         bool newformat;
62         /** The length of the packet. */
63         size_t length;
64         /** The actual packet data. */
65         unsigned char *data;
66 };
67
68 /**
69  * @brief A linked list of OpenPGP packets.
70  *
71  * This structure is used to hold a linked list of packets, for example
72  * all the signatures of a public key's UID.
73  */
74 struct openpgp_packet_list {
75         /** The actual packet structure. */
76         struct openpgp_packet *packet;
77         /** A pointer to the next packet in the list. */
78         struct openpgp_packet_list *next;
79 };
80
81 /**
82  * @brief A packet with signatures.
83  *
84  * This structure holds an OpenPGP packet along with signatures that are
85  * over this packet. It also links to the next signed packet. It's usually
86  * used to hold a UID or subkey with their associated signatures.
87  */
88 struct openpgp_signedpacket_list {
89         /** The OpenPGP packet that's signed. */
90         struct openpgp_packet *packet;
91         /** A linked list of sigs for the packet. */
92         struct openpgp_packet_list *sigs;
93         /** Pointer to the last sig in the sigs linked list */
94         struct openpgp_packet_list *last_sig;
95         /** A pointer to the next packet with signatures. */
96         struct openpgp_signedpacket_list *next;
97 };
98
99 /**
100  * @brief An OpenPGP public key complete with sigs.
101  */
102 struct openpgp_publickey {
103         /** The OpenPGP packet for the public key. */
104         struct openpgp_packet                   *publickey;
105         /** True if the key is revoked. */
106         bool                                     revoked;
107         /** Any signatures directly on the @a publickey packet. */
108         struct openpgp_packet_list              *sigs;
109         /** Pointer to the end of the @a sigs list */
110         struct openpgp_packet_list              *last_sig;
111         /** The list of UIDs with signatures for this key. */
112         struct openpgp_signedpacket_list        *uids;
113         /** Pointer to the end of the @a uids list */
114         struct openpgp_signedpacket_list        *last_uid;
115         /** The list of subkeys with signatures for this key. */
116         struct openpgp_signedpacket_list        *subkeys;
117         /** Pointer to the end of the @a subkey list */
118         struct openpgp_signedpacket_list        *last_subkey;
119         /** The next public key. */
120         struct openpgp_publickey                *next;
121 };
122
123 /**
124  * @brief Holds an SKS key hash (md5 over sorted packet list)
125  */
126 struct skshash {
127         /** The 128 bit MD5 hash of the sorted packet list from the key */
128         uint8_t hash[16];
129 };
130
131 #endif /* __KEYSTRUCTS_H__ */