]> the.earth.li Git - onak.git/blob - keyarray.h
Fix handling of other signature requirement
[onak.git] / keyarray.h
1 /**
2  * @file keyarray.h
3  * @brief Routines to maintain a sorted array of keyids.
4  *
5  * Copyright 2004 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 __KEYARRAY_H__
21 #define __KEYARRAY_H__
22
23 #include <stdbool.h>
24 #include <stdint.h>
25
26 #include "keystructs.h"
27
28 /**
29  * @brief A sorted array of fingerprints
30  *
31  * Holds a sorted list of fingerprints, with room for growth - has details of
32  * both the total size of the array as well as the current number of elements.
33  */
34 struct keyarray {
35         /** The array of key fingerprints */
36         struct openpgp_fingerprint *keys;
37         /** Number of fingerprints in the array */
38         size_t count;
39         /** Total size of the array */
40         size_t size;
41 };
42
43 /**
44  * @brief Given a key array figure out of a key id is present
45  * @param array Pointer to the key array
46  * @param key The keyid to look for
47  */
48 bool array_find(struct keyarray *array, struct openpgp_fingerprint *fp);
49
50 /**
51  * @brief Free a key array
52  * @param array Pointer to the key array to free
53  */
54 void array_free(struct keyarray *array);
55
56 /**
57  * @brief Add a keyid to a key array
58  * @param array Pointer to the key array
59  * @param key The keyid to add
60  *
61  * Checks if the key already exists in the key array and if not adds it.
62  * Returns true if the key was added, false if it was found to be already
63  * present.
64  */
65 bool array_add(struct keyarray *array, struct openpgp_fingerprint *fp);
66
67 /**
68  * @brief Load a file into a keyarray
69  * @param array Pointer to the key array
70  * @param file The full path to the file to load
71  *
72  * Loads fingerprints from the supplied file into the provided keyarray. Does
73  * not re-initialise the array so can be called repeatedly to add multiple
74  * files. The file does not need to be sorted; array_add() is called for each
75  * key to ensure the array is suitable for binary searching with array_find()
76  */
77 bool array_load(struct keyarray *array, const char *file);
78
79 /**
80  * @brief Compare two OpenPGP fingerprints
81  * @param a Fingerprint 1
82  * @param b Fingerprint 2
83  *
84  * Compares 2 OpenPGP fingerprints, returning an integer less than, equal to,
85  * or greater than zero depending on whether a is less than, matches, or is
86  * greater than b.
87  *
88  * For the purposes of comparison shorter fingerprints sort earlier than
89  * longer fingerprints (i.e. v3 < v4 < v5) and comparison of same-length
90  * fingerprints treats them as a numberical value.
91  */
92 int fingerprint_cmp(struct openpgp_fingerprint *a,
93                 struct openpgp_fingerprint *b);
94
95 #endif /* __KEYARRAY_H__ */