]> git.sommitrealweird.co.uk Git - onak.git/blobdiff - parsekey.c
Fix compilation of PostgreSQL backend.
[onak.git] / parsekey.c
index 83fca29f9ce19902756c34fb59895c95b6542ecd..0367e2d1a927dd0f71631e569f5d582b05c8c7eb 100644 (file)
@@ -5,7 +5,7 @@
  *
  * Copyright 2002 Project Purple
  *
  *
  * Copyright 2002 Project Purple
  *
- * $Id: parsekey.c,v 1.16 2003/10/04 10:21:40 noodles Exp $
+ * $Id: parsekey.c,v 1.20 2004/05/27 21:55:38 noodles Exp $
  */
 
 #include <assert.h>
  */
 
 #include <assert.h>
@@ -135,7 +135,7 @@ int parse_keys(struct openpgp_packet_list *packets,
  */
 int debug_packet(struct openpgp_packet *packet)
 {
  */
 int debug_packet(struct openpgp_packet *packet)
 {
-       printf("\tNew format: %d, Tag: %d, Length: %d\n",
+       printf("\tNew format: %d, Tag: %u, Length: %d\n",
                        packet->newformat,
                        packet->tag,
                        packet->length);
                        packet->newformat,
                        packet->tag,
                        packet->length);
@@ -225,13 +225,13 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                                        curpacket->packet->length = curchar;
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
                                        curpacket->packet->length = curchar;
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
-                                       curpacket->packet->length = curchar;
+                                       curpacket->packet->length += curchar;
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
-                                       curpacket->packet->length = curchar;
+                                       curpacket->packet->length += curchar;
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
                                        curpacket->packet->length <<= 8;
                                        rc = getchar_func(ctx, 1, &curchar);
-                                       curpacket->packet->length = curchar;
+                                       curpacket->packet->length += curchar;
                                }
                        } else {
                                curpacket->packet->tag = (curchar & 0x3C) >> 2;
                                }
                        } else {
                                curpacket->packet->tag = (curchar & 0x3C) >> 2;
@@ -292,6 +292,7 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
                } else {
                        logthing(LOGTHING_ERROR, "Unexpected character: 0x%X",
                                curchar);
                } else {
                        logthing(LOGTHING_ERROR, "Unexpected character: 0x%X",
                                curchar);
+                       rc = 1;
                }
        }
 
                }
        }
 
@@ -333,6 +334,28 @@ int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
                                curchar = (packets->packet->length - 192) &
                                         0xFF;
                                putchar_func(ctx, 1, &curchar);
                                curchar = (packets->packet->length - 192) &
                                         0xFF;
                                putchar_func(ctx, 1, &curchar);
+                       } else if (packets->packet->length > 8382 &&
+                               packets->packet->length < 0xFFFFFFFF) {
+                               logthing(LOGTHING_DEBUG,
+                                       "Writing 5 byte length");
+                               curchar = 255;
+                               putchar_func(ctx, 1, &curchar);
+                               
+                               curchar = (packets->packet->length >> 24);
+                               curchar &= 0xFF;
+                               putchar_func(ctx, 1, &curchar);
+                               
+                               curchar = (packets->packet->length >> 16);
+                               curchar &= 0xFF;
+                               putchar_func(ctx, 1, &curchar);
+                               
+                               curchar = (packets->packet->length >> 8);
+                               curchar &= 0xFF;
+                               putchar_func(ctx, 1, &curchar);
+                               
+                               curchar = packets->packet->length;
+                               curchar &= 0xFF;
+                               putchar_func(ctx, 1, &curchar);
                        } else {
                                logthing(LOGTHING_ERROR,
                                        "Unsupported new format length.");
                        } else {
                                logthing(LOGTHING_ERROR,
                                        "Unsupported new format length.");