2 * photoid.c - Routines for OpenPGP id photos.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
8 * $Id: photoid.c,v 1.2 2004/05/27 21:58:18 noodles Exp $
19 #include "keystructs.h"
24 * getphoto - returns an OpenPGP packet containing a photo id.
25 * @key: The key to return the photo id from.
26 * @index: The index of the photo to return.
27 * @photo: The photo data.
28 * @length: The length of the photo data.
30 * This function returns the photo data contained in a supplied key.
31 * index specifies which photo id should be returned. If there's no such
32 * photo id NULL is returned. The returned data pointer refers to the key
33 * data supplied rather than a copy of it.
35 int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
38 struct openpgp_signedpacket_list *curuid = NULL;
43 assert(photo != NULL);
44 assert(length != NULL);
50 while (*photo == NULL && curuid != NULL && i <= index) {
51 if (curuid->packet->tag == 17) {
54 *length = curuid->packet->data[j++];
56 /* length is correct */
57 } else if (*length < 255) {
60 *length += curuid->packet->data[j++];
63 *length = curuid->packet->data[j++];
65 *length += curuid->packet->data[j++];
67 *length += curuid->packet->data[j++];
69 *length += curuid->packet->data[j++];
71 logthing(LOGTHING_DEBUG, "Got photo, size %d",
75 *photo = &(curuid->packet->data[j+16]);
80 curuid = curuid->next;
83 return (*photo != NULL);