Add support for calculating SKS style key hashes
[onak.git] / keystructs.h
1 /*
2  * keystructs.h - Structures for OpenPGP keys
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2002 Project Purple
7  */
8
9 #ifndef __KEYSTRUCTS_H__
10 #define __KEYSTRUCTS_H__
11
12 #include <inttypes.h>
13 #include <stdbool.h>
14 #include <stdlib.h>
15
16 #include "ll.h"
17
18 /**
19  *      struct openpgp_packet - Stores an OpenPGP packet.
20  *      @tag: The packet tag (ie type).
21  *      @newformat: Indicates if this is a new format packet.
22  *      @length: The length of the packet.
23  *      @data: The actual packet
24  *
25  *      This structure holds any form of OpenPGP packet with minimum common
26  *      details decoded out.
27  */
28 struct openpgp_packet {
29         unsigned int tag;
30         bool newformat;
31         size_t length;
32         unsigned char *data;
33 };
34
35 /**
36  *      struct openpgp_packet_list - A linked list of OpenPGP packets.
37  *      @packet: The actual packet structure.
38  *      @next: A pointer to the next packet in the list.
39  *
40  *      This structure is used to hold a linked list of packets, for example
41  *      all the signatures of a public key's UID.
42  */
43 struct openpgp_packet_list {
44         struct openpgp_packet *packet;
45         struct openpgp_packet_list *next;
46 };
47
48 /**
49  *      struct openpgp_signedpacket_list - A packet with signatures.
50  *      @uid: The OpenPGP packet that's signed.
51  *      @sigs: A list of sigs for the packet.
52  *      @next: A pointer to the next packet with signatures.
53  *
54  *      This structure holds an OpenPGP packet along with signatures that are
55  *      over this packet. It also links to the next signed packet. It's usually
56  *      used to hold a UID or subkey with their associated signatures.
57  */
58 struct openpgp_signedpacket_list {
59         struct openpgp_packet *packet;
60         struct openpgp_packet_list *sigs;
61         struct openpgp_packet_list *last_sig;
62         struct openpgp_signedpacket_list *next;
63 };
64
65 /**
66  *      struct openpgp_publickey - An OpenPGP public key complete with sigs.
67  *      @publickey: The OpenPGP packet for the public key.
68  *      @revoked: True if the key is revoked.
69  *      @sigs: Any signatures directly on the publickey packet.
70  *      @uids: The list of UIDs with signatures for this key.
71  *      @subkeys: The list of subkeys with signatures for this key.
72  *      @next: The next public key.
73  */
74 struct openpgp_publickey {
75         struct openpgp_packet                   *publickey;
76         bool                                     revoked;
77         struct openpgp_packet_list              *sigs;
78         struct openpgp_packet_list              *last_sig;
79         struct openpgp_signedpacket_list        *uids;
80         struct openpgp_signedpacket_list        *last_uid;
81         struct openpgp_signedpacket_list        *subkeys;
82         struct openpgp_signedpacket_list        *last_subkey;
83         struct openpgp_publickey                *next;
84 };
85
86 /**
87  *      struct stats_key - holds key details suitable for doing stats on.
88  *      @keyid: The keyid.
89  *      @colour: Used for marking during DFS/BFS.
90  *      @parent: The key that lead us to this one for DFS/BFS.
91  *      @sigs: A linked list of the signatures on this key.
92  *      @gotsigs: A bool indicating if we've initialized the sigs element yet.
93  *      @disabled: If we shouldn't consider the key in calculations.
94  *      @revoked: If the key is revoked (and shouldn't be considered).
95  */
96 struct stats_key {
97         uint64_t keyid;
98         int colour;
99         uint64_t parent;
100         struct ll *sigs;
101         struct ll *signs;
102         bool gotsigs;
103         bool disabled;
104         bool revoked;
105 };
106
107 /**
108  *      struct skshash - holds an SKS key hash (md5 over sorted packet list)
109  *      @hash: The 128 bit MD5 hash of the sorted packet list from the key
110  */
111 struct skshash {
112         uint8_t hash[16];
113 };
114
115 #endif /* __KEYSTRUCTS_H__ */