2 * photoid.c - Routines for OpenPGP id photos.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
17 #include "keystructs.h"
22 * getphoto - returns an OpenPGP packet containing a photo id.
23 * @key: The key to return the photo id from.
24 * @index: The index of the photo to return.
25 * @photo: The photo data.
26 * @length: The length of the photo data.
28 * This function returns the photo data contained in a supplied key.
29 * index specifies which photo id should be returned. If there's no such
30 * photo id NULL is returned. The returned data pointer refers to the key
31 * data supplied rather than a copy of it.
33 int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
36 struct openpgp_signedpacket_list *curuid = NULL;
41 assert(photo != NULL);
42 assert(length != NULL);
48 while (*photo == NULL && curuid != NULL && i <= index) {
49 if (curuid->packet->tag == 17) {
52 *length = curuid->packet->data[j++];
54 /* length is correct */
55 } else if (*length < 255) {
58 *length += curuid->packet->data[j++];
61 *length = curuid->packet->data[j++];
63 *length += curuid->packet->data[j++];
65 *length += curuid->packet->data[j++];
67 *length += curuid->packet->data[j++];
69 logthing(LOGTHING_DEBUG, "Got photo, size %d",
73 *photo = &(curuid->packet->data[j+16]);
78 curuid = curuid->next;
81 return (*photo != NULL);