]> the.earth.li Git - onak.git/blobdiff - parsekey.c
cscvs to tla changeset 96
[onak.git] / parsekey.c
index 4109bb8961aab003c40ab8687e63ae2bd9ffe1b9..ea56f835282905c905b8194db8884cfd83438c07 100644 (file)
@@ -4,6 +4,8 @@
  * Jonathan McDowell <noodles@earth.li>
  *
  * Copyright 2002 Project Purple
+ *
+ * $Id: parsekey.c,v 1.11 2003/09/30 16:58:04 noodles Exp $
  */
 
 #include <assert.h>
@@ -177,6 +179,10 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
        bool                             inpacket = false;
 
        assert(packets != NULL);
+       curpacket = *packets;
+       while (curpacket->next != NULL) {
+               curpacket = curpacket->next;
+       }
 
        while (!rc && !getchar_func(ctx, 1, &curchar)) {
                if (!inpacket && (curchar & 0x80)) {
@@ -201,7 +207,9 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
 
                        curpacket->packet->newformat = (curchar & 0x40);
 
-                       // TODO: Better error checking on getchar_func.
+                       /*
+                        * TODO: Better error checking on getchar_func.
+                        */
                        if (curpacket->packet->newformat) {
                                curpacket->packet->tag = (curchar & 0x3F);
                                rc = getchar_func(ctx, 1, &curchar);
@@ -215,7 +223,9 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                        curpacket->packet->length += 192;
                                } else if (curpacket->packet->length > 223 &&
                                        curpacket->packet->length < 255) {
-                                       printf("Partial length; not supported.\n");
+                                       logthing(LOGTHING_NOTICE,
+                                               "Partial length;"
+                                               " not supported.\n");
                                } else if (curpacket->packet->length == 255) {
                                        /*
                                         * 5 byte length; ie 255 followed by 3
@@ -274,9 +284,16 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                curpacket->packet->data =
                                        malloc(curpacket->packet->length *
                                        sizeof(unsigned char));
-                               rc = getchar_func(ctx,
-                                       curpacket->packet->length,
-                                       curpacket->packet->data);
+                               if (curpacket->packet->data == NULL) {
+                                       logthing(LOGTHING_ERROR, 
+                                               "Can't allocate memory for "
+                                               "packet!");
+                                       rc = -1;
+                               } else {
+                                       rc = getchar_func(ctx,
+                                               curpacket->packet->length,
+                                               curpacket->packet->data);
+                               }
                        }
                        inpacket = false;
                } else {
@@ -354,10 +371,8 @@ int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
                        }
                }
 
-               putchar_func(ctx, packets->packet->length, packets->packet->data);
-//             for (i = 0; i < packets->packet->length; i++) {
-//                     putchar_func(ctx, packets->packet->data[i]);
-//             }
+               putchar_func(ctx, packets->packet->length,
+                               packets->packet->data);
                packets = packets->next;
        }
        return 0;