2 * photoid.c - Routines for OpenPGP id photos.
4 * Copyright 2004 Jonathan McDowell <noodles@earth.li>
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #include "keystructs.h"
32 * getphoto - returns an OpenPGP packet containing a photo id.
33 * @key: The key to return the photo id from.
34 * @index: The index of the photo to return.
35 * @photo: The photo data.
36 * @length: The length of the photo data.
38 * This function returns the photo data contained in a supplied key.
39 * index specifies which photo id should be returned. If there's no such
40 * photo id NULL is returned. The returned data pointer refers to the key
41 * data supplied rather than a copy of it.
43 onak_status_t getphoto(struct openpgp_publickey *key, int index,
44 unsigned char **photo, size_t *length)
46 struct openpgp_signedpacket_list *curuid = NULL;
50 if (key == NULL || photo == NULL || length == NULL)
51 return ONAK_E_INVALID_PARAM;
57 while (*photo == NULL && curuid != NULL && i <= index) {
58 if (curuid->packet->tag == 17) {
61 *length = curuid->packet->data[j++];
63 /* length is correct */
64 } else if (*length < 255) {
67 *length += curuid->packet->data[j++];
70 *length = curuid->packet->data[j++];
72 *length += curuid->packet->data[j++];
74 *length += curuid->packet->data[j++];
76 *length += curuid->packet->data[j++];
80 *photo = &(curuid->packet->data[j+16]);
85 curuid = curuid->next;
88 return *photo == NULL ? ONAK_E_NOT_FOUND : ONAK_E_OK;