+
+/*
+ * TODO: Abstract out; all our linked lists should be generic and then we can
+ * llsize them.
+ */
+int spsize(struct openpgp_signedpacket_list *list)
+{
+ int size = 0;
+ struct openpgp_signedpacket_list *cur;
+
+ for (cur = list; cur != NULL; cur = cur->next, size++) ;
+
+ return size;
+}
+
+/**
+ * keyuids - Takes a key and returns an array of its UIDs
+ * @key: The key to get the uids of.
+ * @primary: A pointer to store the primary UID in.
+ *
+ * keyuids takes a public key structure and builds an array of the UIDs
+ * on the key. It also attempts to work out the primary UID and returns a
+ * separate pointer to that particular element of the array.
+ */
+char **keyuids(struct openpgp_publickey *key, char **primary)
+{
+ struct openpgp_signedpacket_list *curuid = NULL;
+ char buf[1024];
+ char **uids = NULL;
+ int count = 0;
+
+ if (key != NULL && key->uids != NULL) {
+ uids = malloc((spsize(key->uids) + 1) * sizeof (char *));
+
+ curuid = key->uids;
+ while (curuid != NULL) {
+ buf[0] = 0;
+ if (curuid->packet->tag == 13) {
+ snprintf(buf, 1023, "%.*s",
+ (int) curuid->packet->length,
+ curuid->packet->data);
+ uids[count++] = strdup(buf);
+ }
+ curuid = curuid -> next;
+ }
+ uids[count] = NULL;
+ }
+ /*
+ * TODO: Parse subpackets for real primary ID (v4 keys)
+ */
+ if (primary != NULL) {
+ *primary = uids[0];
+ }
+
+ return uids;
+}