Commit 9c7a001a authored by Niels Möller's avatar Niels Möller

New pgp-encode helper function, write_string.

parent 96f1348e
2016-08-16 Niels Möller <nisse@lysator.liu.se> 2016-08-16 Niels Möller <nisse@lysator.liu.se>
* pgp-encode.c (write_string): New helper function, replacing...
(WRITE): ... deleted macro.
* examples/io.c (write_data): Renamed, and use const void * for * examples/io.c (write_data): Renamed, and use const void * for
the input data. Updated all callers. the input data. Updated all callers.
(write_string): ... old name. (write_string): ... old name.
......
...@@ -339,7 +339,11 @@ pgp_crc24(unsigned length, const uint8_t *data) ...@@ -339,7 +339,11 @@ pgp_crc24(unsigned length, const uint8_t *data)
} }
#define WRITE(buffer, s) (nettle_buffer_write(buffer, strlen((s)), (s))) static int
write_string (struct nettle_buffer *buffer, const char *s)
{
return nettle_buffer_write(buffer, strlen((s)), (const uint8_t *) (s));
}
/* 15 base 64 groups data per line */ /* 15 base 64 groups data per line */
#define BINARY_PER_LINE 45 #define BINARY_PER_LINE 45
...@@ -357,9 +361,9 @@ pgp_armor(struct nettle_buffer *buffer, ...@@ -357,9 +361,9 @@ pgp_armor(struct nettle_buffer *buffer,
base64_encode_init(&ctx); base64_encode_init(&ctx);
if (! (WRITE(buffer, "BEGIN PGP ") if (! (write_string(buffer, "BEGIN PGP ")
&& WRITE(buffer, tag) && write_string(buffer, tag)
&& WRITE(buffer, "\nComment: Nettle\n\n"))) && write_string(buffer, "\nComment: Nettle\n\n")))
return 0; return 0;
for (; for (;
...@@ -414,7 +418,7 @@ pgp_armor(struct nettle_buffer *buffer, ...@@ -414,7 +418,7 @@ pgp_armor(struct nettle_buffer *buffer,
base64_encode_group(p, crc); base64_encode_group(p, crc);
} }
return (WRITE(buffer, "\nBEGIN PGP ") return (write_string(buffer, "\nBEGIN PGP ")
&& WRITE(buffer, tag) && write_string(buffer, tag)
&& NETTLE_BUFFER_PUTC(buffer, '\n')); && NETTLE_BUFFER_PUTC(buffer, '\n'));
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment