X-Git-Url: http://the.earth.li/gitweb/?p=onak.git;a=blobdiff_plain;f=keyarray.h;h=1ac13ba571c68d0190a5aa92bdf44d5e3ea9bbf8;hp=86c5991f2777721e20ea043056b13b1aaa37db92;hb=743957a08f068529d3add3e8485678b4e5034195;hpb=5e1b22d763640c4d7a09d07920403d8d491b4410 diff --git a/keyarray.h b/keyarray.h index 86c5991..1ac13ba 100644 --- a/keyarray.h +++ b/keyarray.h @@ -1,5 +1,6 @@ -/* - * keyarray.h - routines to maintain a sorted array of keyids. +/** + * @file keyarray.h + * @brief Routines to maintain a sorted array of keyids. * * Copyright 2004 Jonathan McDowell * @@ -13,8 +14,7 @@ * more details. * * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 51 - * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * this program. If not, see . */ #ifndef __KEYARRAY_H__ @@ -23,14 +23,73 @@ #include #include +#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 { - uint64_t *keys; + /** 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; }; -bool array_find(struct keyarray *array, uint64_t key); +/** + * @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); -bool array_add(struct keyarray *array, uint64_t key); + +/** + * @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__ */