]> the.earth.li Git - onak.git/blob - keyarray.h
Fix issue with looking up keys by fingerprint via HKP interface
[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, write to the Free Software Foundation, Inc., 51
18  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef __KEYARRAY_H__
22 #define __KEYARRAY_H__
23
24 #include <stdbool.h>
25 #include <stdint.h>
26
27 #include "keystructs.h"
28
29 /**
30  * @brief A sorted array of fingerprints
31  *
32  * Holds a sorted list of fingerprints, with room for growth - has details of
33  * both the total size of the array as well as the current number of elements.
34  */
35 struct keyarray {
36         /** The array of key fingerprints */
37         struct openpgp_fingerprint *keys;
38         /** Number of fingerprints in the array */
39         size_t count;
40         /** Total size of the array */
41         size_t size;
42 };
43
44 /**
45  * @brief Given a key array figure out of a key id is present
46  * @param array Pointer to the key array
47  * @param key The keyid to look for
48  */
49 bool array_find(struct keyarray *array, struct openpgp_fingerprint *fp);
50
51 /**
52  * @brief Free a key array
53  * @param array Pointer to the key array to free
54  */
55 void array_free(struct keyarray *array);
56
57 /**
58  * @brief Add a keyid to a key array
59  * @param array Pointer to the key array
60  * @param key The keyid to add
61  *
62  * Checks if the key already exists in the key array and if not adds it.
63  * Returns true if the key was added, false if it was found to be already
64  * present.
65  */
66 bool array_add(struct keyarray *array, struct openpgp_fingerprint *fp);
67
68 #endif /* __KEYARRAY_H__ */