summaryrefslogtreecommitdiff
path: root/pgp-encode.c
diff options
context:
space:
mode:
authorNiels Möller <nisse@lysator.liu.se>2002-10-19 12:48:14 +0200
committerNiels Möller <nisse@lysator.liu.se>2002-10-19 12:48:14 +0200
commita35ccc950e808249f831cccd0b701647d7f0a0c1 (patch)
treec157b43f6a4b26f351e67f34be3a86ff4579606a /pgp-encode.c
parentbb34f1ed71b7ef43e81fc9490fa9d18968411aa1 (diff)
downloadnettle-a35ccc950e808249f831cccd0b701647d7f0a0c1.tar.gz
(pgp_armor): Use new base64 conventions.
Rev: src/nettle/pgp-encode.c:1.2
Diffstat (limited to 'pgp-encode.c')
-rw-r--r--pgp-encode.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/pgp-encode.c b/pgp-encode.c
index 9471d07e..297f20b5 100644
--- a/pgp-encode.c
+++ b/pgp-encode.c
@@ -329,10 +329,9 @@ pgp_crc24(unsigned length, const uint8_t *data)
#define WRITE(buffer, s) (nettle_buffer_write(buffer, strlen((s)), (s)))
-/* Base 64 groups data per line */
-#define GROUPS_PER_LINE 15
-#define BINARY_PER_LINE (GROUPS_PER_LINE * BASE64_BINARY_BLOCK_SIZE)
-#define TEXT_PER_LINE (GROUPS_PER_LINE * BASE64_BINARY_BLOCK_SIZE)
+/* 15 base 64 groups data per line */
+#define BINARY_PER_LINE 45
+#define TEXT_PER_LINE BASE64_ENCODE_LENGTH(BINARY_PER_LINE)
int
pgp_armor(struct nettle_buffer *buffer,
@@ -340,7 +339,11 @@ pgp_armor(struct nettle_buffer *buffer,
unsigned length,
const uint8_t *data)
{
+ struct base64_encode_ctx ctx;
+
unsigned crc = pgp_crc24(length, data);
+
+ base64_encode_init(&ctx);
if (! (WRITE(buffer, "BEGIN PGP ")
&& WRITE(buffer, tag)
@@ -351,28 +354,40 @@ pgp_armor(struct nettle_buffer *buffer,
length >= BINARY_PER_LINE;
length -= BINARY_PER_LINE, data += BINARY_PER_LINE)
{
+ unsigned done;
uint8_t *p
= nettle_buffer_space(buffer, TEXT_PER_LINE);
if (!p)
return 0;
- base64_encode(p, BINARY_PER_LINE, data);
+ done = base64_encode_update(&ctx, p, BINARY_PER_LINE, data);
+ assert(done <= TEXT_PER_LINE);
+ /* FIXME: Create some official way to do this */
+ buffer->size -= (TEXT_PER_LINE - done);
+
if (!NETTLE_BUFFER_PUTC(buffer, '\n'))
return 0;
}
if (length)
{
- unsigned text_size = BASE64_ENCODE_LENGTH(length);
-
+ unsigned text_size = BASE64_ENCODE_LENGTH(length)
+ + BASE64_ENCODE_FINAL_LENGTH;
+ unsigned done;
+
uint8_t *p
= nettle_buffer_space(buffer, text_size);
if (!p)
return 0;
- base64_encode(p, length, data);
+ done = base64_encode_update(&ctx, p, length, data);
+ done += base64_encode_final(&ctx, p + done);
+
+ /* FIXME: Create some official way to do this */
+ buffer->size -= (text_size - done);
+
if (!NETTLE_BUFFER_PUTC(buffer, '\n'))
return 0;
}