cscvs to tla changeset 125
[onak.git] / photoid.c
1 /*
2  * photoid.c - Routines for OpenPGP id photos.
3  *
4  * Jonathan McDowell <noodles@earth.li>
5  *
6  * Copyright 2004 Project Purple
7  *
8  * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $
9  */
10
11 #include <assert.h>
12 #include <inttypes.h>
13 #include <stdbool.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16
17 #include "keyid.h"
18 #include "keyindex.h"
19 #include "keystructs.h"
20
21 /**
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  *
26  *      This function returns the OpenPGP packet containing a photo id from a
27  *      supplied key. index specifies which photo id should be returned. If
28  *      there's no such photo id NULL is returned.
29  */
30 struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
31 {
32         struct openpgp_signedpacket_list *curuid = NULL;
33         struct openpgp_packet            *photo = NULL;
34         int                               i = 0;
35
36         assert(key != NULL);
37
38         curuid = key->uids;
39         i = 0;
40         while (photo == NULL && curuid != NULL && i <= index) {
41                 if (curuid->packet->tag == 17) {
42                         if (i == index) {
43                                 photo = curuid->packet;
44                         } else {
45                                 i++;
46                         }
47                 }
48                 curuid = curuid->next;
49         }
50
51         return photo;
52 }