Use C99 uint32_t rather than u_int32_t
[onak.git] / armor.c
diff --git a/armor.c b/armor.c
index e24787e122d878777a0e8ed88c4580c40796a785..a730acd83bbfd1b2a8ed994b3fa1c7d6fd107c52 100644 (file)
--- a/armor.c
+++ b/armor.c
@@ -1,20 +1,30 @@
 /*
  * armor.c - Routines to (de)armor OpenPGP packet streams.
  *
- * Jonathan McDowell <noodles@earth.li>
+ * Copyright 2002-2004, 2011 Jonathan McDowell <noodles@earth.li>
  *
- * Copyright 2002 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: armor.c,v 1.8 2003/11/01 19:23:38 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 <stdlib.h>
 
 #include "armor.h"
 #include "keystructs.h"
+#include "log.h"
 #include "onak-conf.h"
 #include "parsekey.h"
+#include "version.h"
 
 #define ARMOR_WIDTH 64
 
@@ -36,7 +46,7 @@ static unsigned char encode64(unsigned char c) {
        } else if (c == 63) {
                c = '/';
        } else {
-               assert(c < 64);
+               log_assert(c < 64);
        }
 
        return c;
@@ -78,7 +88,7 @@ struct armor_context {
        int curoctet;
        int count;
        long crc24;
-       int (*putchar_func)(void *ctx, size_t count, unsigned char *c);
+       int (*putchar_func)(void *ctx, size_t count, void *c);
        void *ctx;
 };
 
@@ -144,7 +154,7 @@ static int armor_putchar_int(void *ctx, unsigned char c)
        unsigned char t;
        int i;
 
-       assert(ctx != NULL);
+       log_assert(ctx != NULL);
        state = (struct armor_context *) ctx;
 
        switch (state->curoctet++) {
@@ -185,12 +195,14 @@ static int armor_putchar_int(void *ctx, unsigned char c)
 }
 
 
-static int armor_putchar(void *ctx, size_t count, unsigned char *c)
+static int armor_putchar(void *ctx, size_t count, void *c)
 {
        int i;
 
+       log_assert(c != NULL);
+
        for (i = 0; i < count; i++) {
-               armor_putchar_int(ctx, c[i]);
+               armor_putchar_int(ctx, ((char *) c)[i]);
        }
        
        return 0;
@@ -209,7 +221,7 @@ struct dearmor_context {
        int curoctet;
        int count;
        long crc24;
-       int (*getchar_func)(void *ctx, size_t count, unsigned char *c);
+       int (*getchar_func)(void *ctx, size_t count, void *c);
        void *ctx;
 };
 
@@ -245,7 +257,7 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
        unsigned char tmpc;
        int i;
 
-       assert(ctx != NULL);
+       log_assert(ctx != NULL);
        state = (struct dearmor_context *) ctx;
        *c = 0;
        
@@ -290,12 +302,12 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
        return (tmpc == 64);
 }
 
-static int dearmor_getchar_c(void *ctx, size_t count, unsigned char *c)
+static int dearmor_getchar_c(void *ctx, size_t count, void *c)
 {
        int i, rc = 0;
 
        for (i = 0; i < count && rc == 0; i++) {
-               rc = dearmor_getchar(ctx, &c[i]);
+               rc = dearmor_getchar(ctx, &((unsigned char *) c)[i]);
        }
 
        return rc;
@@ -311,7 +323,7 @@ static int dearmor_getchar_c(void *ctx, size_t count, unsigned char *c)
  *     using putchar_func.
  */
 int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list *packets)
 {
@@ -322,8 +334,8 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
         */
        putchar_func(ctx, sizeof("-----BEGIN PGP PUBLIC KEY BLOCK-----\n") - 1,
                (unsigned char *) "-----BEGIN PGP PUBLIC KEY BLOCK-----\n");
-       putchar_func(ctx, sizeof("Version: onak " VERSION "\n\n") - 1,
-               (unsigned char *) "Version: onak " VERSION "\n\n");
+       putchar_func(ctx, sizeof("Version: onak " ONAK_VERSION "\n\n") - 1,
+               (unsigned char *) "Version: onak " ONAK_VERSION "\n\n");
        
        armor_init(&armor_ctx);
        armor_ctx.putchar_func = putchar_func;
@@ -351,7 +363,7 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
  *     packets.
  */
 int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list **packets)
 {