]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - photoid.c
Switch debian build system to dh
[onak.git] / photoid.c
index 4416e3e35f7c17d1cd33242139da9fe3da4a9ae6..2501f4a10629557e41e6817d8aa98ccc5f801046 100644 (file)
--- a/photoid.c
+++ b/photoid.c
@@ -1,14 +1,22 @@
 /*
  * photoid.c - Routines for OpenPGP id photos.
  *
 /*
  * photoid.c - Routines for OpenPGP id photos.
  *
- * Jonathan McDowell <noodles@earth.li>
+ * Copyright 2004 Jonathan McDowell <noodles@earth.li>
  *
  *
- * Copyright 2004 Project Purple
+ * 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.
  *
  *
- * $Id: photoid.c,v 1.1 2004/05/27 01:25:37 noodles Exp $
+ * 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, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
  */
 
-#include <assert.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <inttypes.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include "keyid.h"
 #include "keyindex.h"
 #include "keystructs.h"
 #include "keyid.h"
 #include "keyindex.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.
 
 /**
  *     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)
+onak_status_t getphoto(struct openpgp_publickey *key, int index,
+               unsigned char **photo, size_t *length)
 {
        struct openpgp_signedpacket_list *curuid = NULL;
 {
        struct openpgp_signedpacket_list *curuid = NULL;
-       struct openpgp_packet            *photo = NULL;
        int                               i = 0;
        int                               i = 0;
+       int                               j = 0;
 
 
-       assert(key != NULL);
+       if (key == NULL || photo == NULL || length == NULL)
+               return ONAK_E_INVALID_PARAM;
 
 
+       *photo = NULL;
+       
        curuid = key->uids;
        i = 0;
        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) {
                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++];
+                               }
+                               j++;
+                               *length -= 17;
+                               *photo = &(curuid->packet->data[j+16]);
                        } else {
                                i++;
                        }
                        } else {
                                i++;
                        }
@@ -48,5 +85,5 @@ struct openpgp_packet *getphoto(struct openpgp_publickey *key, int index)
                curuid = curuid->next;
        }
 
                curuid = curuid->next;
        }
 
-       return photo;
+       return *photo == NULL ? ONAK_E_NOT_FOUND : ONAK_E_OK;
 }
 }