X-Git-Url: https://the.earth.li/gitweb/?a=blobdiff_plain;f=armor.c;h=6d3fc138f6bee1445f9ac9fea4a0f20139723468;hb=ed841dbf668ab9b92868064f0baada6c922322a8;hp=3f47f64f01637a46b14390a658f557e71a555ea6;hpb=05d5b193ee05a187d4f3fd05a4be1fbb6bf937b6;p=onak.git diff --git a/armor.c b/armor.c index 3f47f64..6d3fc13 100644 --- a/armor.c +++ b/armor.c @@ -4,15 +4,13 @@ * Jonathan McDowell * * Copyright 2002 Project Purple - * - * $Id: armor.c,v 1.6 2003/06/07 13:45:34 noodles Exp $ */ -#include #include #include "armor.h" #include "keystructs.h" +#include "log.h" #include "onak-conf.h" #include "parsekey.h" @@ -36,7 +34,7 @@ static unsigned char encode64(unsigned char c) { } else if (c == 63) { c = '/'; } else { - assert(c < 64); + log_assert(c < 64); } return c; @@ -102,16 +100,28 @@ static void armor_finish(struct armor_context *state) state->putchar_func(state->ctx, 1, &c); state->putchar_func(state->ctx, 1, (unsigned char *) "="); state->putchar_func(state->ctx, 1, (unsigned char *) "="); + state->count += 3; + if ((state->count % ARMOR_WIDTH) == 0) { + state->putchar_func(state->ctx, 1, + (unsigned char *) "\n"); + } break; case 2: c = encode64((state->lastoctet & 0xF) << 2); state->putchar_func(state->ctx, 1, &c); state->putchar_func(state->ctx, 1, (unsigned char *) "="); + state->count += 2; + if ((state->count % ARMOR_WIDTH) == 0) { + state->putchar_func(state->ctx, 1, + (unsigned char *) "\n"); + } break; } state->crc24 &= 0xffffffL; - state->putchar_func(state->ctx, 1, (unsigned char *) "\n"); + if ((state->count % ARMOR_WIDTH) != 0) { + state->putchar_func(state->ctx, 1, (unsigned char *) "\n"); + } state->putchar_func(state->ctx, 1, (unsigned char *) "="); c = encode64(state->crc24 >> 18); state->putchar_func(state->ctx, 1, &c); @@ -132,7 +142,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++) { @@ -233,7 +243,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; @@ -396,7 +406,8 @@ int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count, dearmor_init(&dearmor_ctx); dearmor_ctx.getchar_func = getchar_func; dearmor_ctx.ctx = ctx; - read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx, packets); + read_openpgp_stream(dearmor_getchar_c, &dearmor_ctx, + packets, 0); dearmor_finish(&dearmor_ctx); /* * TODO: Look for armor footer