X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/1e5cdbdd102555b43fc3ffa9a45ba9e7a833c190..6a420d96a080e04da6c441f88cc52e60fe661089:/sbr/base64.c diff --git a/sbr/base64.c b/sbr/base64.c index cbd225de..8fb5357e 100644 --- a/sbr/base64.c +++ b/sbr/base64.c @@ -5,9 +5,9 @@ * complete copyright information. */ -#include -#include -#include +#include "h/mh.h" +#include "error.h" +#include "h/mime.h" #include static const char nib2b64[0x40+1] = @@ -29,8 +29,8 @@ writeBase64aux (FILE *in, FILE *out, int crlf) { unsigned int cc, n; unsigned char inbuf[3]; - int skipnl = 0; + bool skipnl = false; n = BPERLIN; while ((cc = fread (inbuf, sizeof(*inbuf), sizeof(inbuf), in)) > 0) { unsigned long bits; @@ -69,7 +69,7 @@ writeBase64aux (FILE *in, FILE *out, int crlf) inbuf[cc++] = '\n'; else ungetc('\n', in); - skipnl = 1; + skipnl = true; } else { /* This only works as long as sizeof(inbuf) == 3 */ ungetc(inbuf[cc - 1], in); @@ -78,7 +78,7 @@ writeBase64aux (FILE *in, FILE *out, int crlf) inbuf[++i] = '\n'; } } else { - skipnl = 0; + skipnl = false; } } } @@ -244,26 +244,22 @@ static const unsigned char b642nib[0x80] = { * len - number of decoded bytes * skip-crs - non-zero for text content, and for which CR's should be * skipped - * digest - for an MD5 digest, it can be null */ int decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len, - int skip_crs, unsigned char *digest) { + int skip_crs) +{ const char *cp = encoded; - int self_delimiting = 0; int bitno, skip; uint32_t bits; /* Size the decoded string very conservatively. */ charstring_t decoded_c = charstring_create (strlen (encoded)); - MD5_CTX mdContext; - - if (digest) - MD5Init (&mdContext); bitno = 18; bits = 0L; skip = 0; + bool self_delimiting = false; for (; *cp; ++cp) { switch (*cp) { unsigned char value; @@ -290,22 +286,16 @@ test_end: if (! skip_crs || b != '\r') { charstring_push_back (decoded_c, b); } - if (digest) - MD5Update (&mdContext, (unsigned char *) &b, 1); if (skip < 2) { b = (bits >> 8) & 0xff; if (! skip_crs || b != '\r') { charstring_push_back (decoded_c, b); } - if (digest) - MD5Update (&mdContext, (unsigned char *) &b, 1); if (skip < 1) { b = bits & 0xff; if (! skip_crs || b != '\r') { charstring_push_back (decoded_c, b); } - if (digest) - MD5Update (&mdContext, (unsigned char *) &b, 1); } } @@ -318,7 +308,7 @@ test_end: case '=': if (++skip <= 3) goto test_end; - self_delimiting = 1; + self_delimiting = true; break; } } @@ -337,10 +327,6 @@ test_end: *len = charstring_bytes (decoded_c); charstring_free (decoded_c); - if (digest) { - MD5Final (digest, &mdContext); - } - return OK; } @@ -351,7 +337,8 @@ test_end: * is allocated by the function and must be freed by the caller. */ void -hexify (const unsigned char *input, size_t len, char **output) { +hexify (const unsigned char *input, size_t len, char **output) +{ /* Start with a charstring capacity that's arbitrarily larger than len. */ const charstring_t tmp = charstring_create (2 * len); const unsigned char *cp = input;