-
Notifications
You must be signed in to change notification settings - Fork 0
/
photoid.c
83 lines (76 loc) · 2.41 KB
/
photoid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* photoid.c - Routines for OpenPGP id photos.
*
* Copyright 2004 Jonathan McDowell <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include "keystructs.h"
#include "onak.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 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.
*/
onak_status_t getphoto(struct openpgp_publickey *key, int index,
unsigned char **photo, size_t *length)
{
struct openpgp_signedpacket_list *curuid = NULL;
int i = 0;
int j = 0;
if (key == NULL || photo == NULL || length == NULL)
return ONAK_E_INVALID_PARAM;
*photo = NULL;
curuid = key->uids;
i = 0;
while (*photo == NULL && curuid != NULL && i <= index) {
if (curuid->packet->tag == 17) {
if (i == index) {
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++];
}
j++;
*length -= 17;
*photo = &(curuid->packet->data[j+16]);
} else {
i++;
}
}
curuid = curuid->next;
}
return *photo == NULL ? ONAK_E_NOT_FOUND : ONAK_E_OK;
}