2 * photoid.c - Routines for OpenPGP id photos.
4 * Jonathan McDowell <noodles@earth.li>
6 * Copyright 2004 Project Purple
16 #include "keystructs.h"
21 * getphoto - returns an OpenPGP packet containing a photo id.
22 * @key: The key to return the photo id from.
23 * @index: The index of the photo to return.
24 * @photo: The photo data.
25 * @length: The length of the photo data.
27 * This function returns the photo data contained in a supplied key.
28 * index specifies which photo id should be returned. If there's no such
29 * photo id NULL is returned. The returned data pointer refers to the key
30 * data supplied rather than a copy of it.
32 int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo,
35 struct openpgp_signedpacket_list *curuid = NULL;
39 log_assert(key != NULL);
40 log_assert(photo != NULL);
41 log_assert(length != NULL);
47 while (*photo == NULL && curuid != NULL && i <= index) {
48 if (curuid->packet->tag == 17) {
51 *length = curuid->packet->data[j++];
53 /* length is correct */
54 } else if (*length < 255) {
57 *length += curuid->packet->data[j++];
60 *length = curuid->packet->data[j++];
62 *length += curuid->packet->data[j++];
64 *length += curuid->packet->data[j++];
66 *length += curuid->packet->data[j++];
68 logthing(LOGTHING_DEBUG, "Got photo, size %d",
72 *photo = &(curuid->packet->data[j+16]);
77 curuid = curuid->next;
80 return (*photo != NULL);