X-Git-Url: https://git.sommitrealweird.co.uk/onak.git/blobdiff_plain/42d43e0ec08e249cecf74ec448cb6405b3c89d84..e1385087ec060568a966a5305a9d88c24a2a0a55:/photoid.c?ds=sidebyside diff --git a/photoid.c b/photoid.c index 4416e3e..dd28753 100644 --- a/photoid.c +++ b/photoid.c @@ -4,11 +4,8 @@ * Jonathan McDowell * * Copyright 2004 Project Purple - * - * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $ */ -#include #include #include #include @@ -17,30 +14,62 @@ #include "keyid.h" #include "keyindex.h" #include "keystructs.h" +#include "log.h" +#include "photoid.h" /** * getphoto - returns an OpenPGP packet containing a photo id. * @key: The key to return the photo id from. * @index: The index of the photo to return. + * @photo: The photo data. + * @length: The length of the photo data. * - * This function returns the OpenPGP packet containing a photo id from a - * supplied key. index specifies which photo id should be returned. If - * there's no such photo id NULL is returned. + * This function returns the photo data contained in a supplied key. + * index specifies which photo id should be returned. If there's no such + * photo id NULL is returned. The returned data pointer refers to the key + * data supplied rather than a copy of it. */ -struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index) +int getphoto(struct openpgp_publickey *key, int index, unsigned char **photo, + size_t *length) { struct openpgp_signedpacket_list *curuid = NULL; - struct openpgp_packet *photo = NULL; int i = 0; + int j = 0; - assert(key != NULL); + log_assert(key != NULL); + log_assert(photo != NULL); + log_assert(length != NULL); + *photo = NULL; + curuid = key->uids; i = 0; - while (photo == NULL && curuid != NULL && i <= index) { + while (*photo == NULL && curuid != NULL && i <= index) { if (curuid->packet->tag == 17) { if (i == index) { - photo = curuid->packet; + j = 0; + *length = curuid->packet->data[j++]; + if (*length < 192) { + /* length is correct */ + } else if (*length < 255) { + *length -= 192; + *length <<= 8; + *length += curuid->packet->data[j++]; + *length += 192; + } else { + *length = curuid->packet->data[j++]; + *length <<= 8; + *length += curuid->packet->data[j++]; + *length <<= 8; + *length += curuid->packet->data[j++]; + *length <<= 8; + *length += curuid->packet->data[j++]; + } + logthing(LOGTHING_DEBUG, "Got photo, size %d", + *length); + j++; + *length -= 17; + *photo = &(curuid->packet->data[j+16]); } else { i++; } @@ -48,5 +77,5 @@ struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index) curuid = curuid->next; } - return photo; + return (*photo != NULL); }