summaryrefslogtreecommitdiff
path: root/gl/lib/base64.h
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2007-01-04 11:52:52 +0100
committerJim Meyering <jim@meyering.net>2007-01-04 11:52:52 +0100
commit3b933f1e33197fec6a59466df1337292ec7bfa56 (patch)
tree407732a747d2622577c8366b93a01744dfa8845b /gl/lib/base64.h
parent99d9e13b9c7e53db7620e5b34550a114adfa22d3 (diff)
downloadcoreutils-3b933f1e33197fec6a59466df1337292ec7bfa56.tar.xz
[ChangeLog]
When decoding, always allow newlines in input, with almost no performance impact. * src/base64.c (do_decode): Initialize decode context. Call base64_decode one more time, after all input is processed. (usage): When decoding, newlines are always accepted. * tests/misc/base64: Add a bunch of tests, for the above. * gl/lib/base64.c: Include <string.h>. (base64_decode_ctx_init, get_4, decode_4): New functions. (base64_decode): Efficiently handle interspersed newlines. (base64_decode_alloc): Update signature. * gl/lib/base64.h (struct base64_decode_context): Define. (base64_decode_ctx_init): Add prototype. (base64_decode, base64_decode_alloc): Update prototypes. [doc/ChangeLog] * coreutils.texi (base64 invocation): When decoding, newlines are always accepted.
Diffstat (limited to 'gl/lib/base64.h')
-rw-r--r--gl/lib/base64.h13
1 files changed, 11 insertions, 2 deletions
diff --git a/gl/lib/base64.h b/gl/lib/base64.h
index 6bb9a97f5..be858eaaf 100644
--- a/gl/lib/base64.h
+++ b/gl/lib/base64.h
@@ -29,6 +29,12 @@
integer >= n/k, i.e., the ceiling of n/k. */
# define BASE64_LENGTH(inlen) ((((inlen) + 2) / 3) * 4)
+struct base64_decode_context
+{
+ unsigned int i;
+ char buf[4];
+};
+
extern bool isbase64 (char ch);
extern void base64_encode (const char *restrict in, size_t inlen,
@@ -36,10 +42,13 @@ extern void base64_encode (const char *restrict in, size_t inlen,
extern size_t base64_encode_alloc (const char *in, size_t inlen, char **out);
-extern bool base64_decode (const char *restrict in, size_t inlen,
+extern void base64_decode_ctx_init (struct base64_decode_context *ctx);
+extern bool base64_decode (struct base64_decode_context *ctx,
+ const char *restrict in, size_t inlen,
char *restrict out, size_t *outlen);
-extern bool base64_decode_alloc (const char *in, size_t inlen,
+extern bool base64_decode_alloc (struct base64_decode_context *ctx,
+ const char *in, size_t inlen,
char **out, size_t *outlen);
#endif /* BASE64_H */