File: keyarray.h

package info (click to toggle)
onak 0.6.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,280 kB
  • sloc: ansic: 13,824; sh: 403; perl: 301; sql: 21; makefile: 19
file content (95 lines) | stat: -rw-r--r-- 3,067 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
 * @file keyarray.h
 * @brief Routines to maintain a sorted array of keyids.
 *
 * Copyright 2004 Jonathan McDowell <noodles@earth.li>
 *
 * This program is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef __KEYARRAY_H__
#define __KEYARRAY_H__

#include <stdbool.h>
#include <stdint.h>

#include "keystructs.h"

/**
 * @brief A sorted array of fingerprints
 *
 * Holds a sorted list of fingerprints, with room for growth - has details of
 * both the total size of the array as well as the current number of elements.
 */
struct keyarray {
	/** The array of key fingerprints */
	struct openpgp_fingerprint *keys;
	/** Number of fingerprints in the array */
	size_t count;
	/** Total size of the array */
	size_t size;
};

/**
 * @brief Given a key array figure out of a key id is present
 * @param array Pointer to the key array
 * @param key The keyid to look for
 */
bool array_find(struct keyarray *array, struct openpgp_fingerprint *fp);

/**
 * @brief Free a key array
 * @param array Pointer to the key array to free
 */
void array_free(struct keyarray *array);

/**
 * @brief Add a keyid to a key array
 * @param array Pointer to the key array
 * @param key The keyid to add
 *
 * Checks if the key already exists in the key array and if not adds it.
 * Returns true if the key was added, false if it was found to be already
 * present.
 */
bool array_add(struct keyarray *array, struct openpgp_fingerprint *fp);

/**
 * @brief Load a file into a keyarray
 * @param array Pointer to the key array
 * @param file The full path to the file to load
 *
 * Loads fingerprints from the supplied file into the provided keyarray. Does
 * not re-initialise the array so can be called repeatedly to add multiple
 * files. The file does not need to be sorted; array_add() is called for each
 * key to ensure the array is suitable for binary searching with array_find()
 */
bool array_load(struct keyarray *array, const char *file);

/**
 * @brief Compare two OpenPGP fingerprints
 * @param a Fingerprint 1
 * @param b Fingerprint 2
 *
 * Compares 2 OpenPGP fingerprints, returning an integer less than, equal to,
 * or greater than zero depending on whether a is less than, matches, or is
 * greater than b.
 *
 * For the purposes of comparison shorter fingerprints sort earlier than
 * longer fingerprints (i.e. v3 < v4 < v5) and comparison of same-length
 * fingerprints treats them as a numberical value.
 */
int fingerprint_cmp(struct openpgp_fingerprint *a,
		struct openpgp_fingerprint *b);

#endif /* __KEYARRAY_H__ */