]> diplodocus.org Git - nmh/blobdiff - sbr/base64.c
expect this commit to be force-replaced periodically
[nmh] / sbr / base64.c
index 2afad491afbfccb41d404d109adc777feff09b96..0de4a85f802c90db6ee6849c727bb0726cf900e0 100644 (file)
@@ -5,9 +5,9 @@
  * complete copyright information.
  */
 
  * complete copyright information.
  */
 
-#include <h/mh.h>
-#include <h/mime.h>
-#include <h/md5.h>
+#include "h/mh.h"
+#include "error.h"
+#include "h/mime.h"
 #include <inttypes.h>
 
 static const char nib2b64[0x40+1] =
 #include <inttypes.h>
 
 static const char nib2b64[0x40+1] =
@@ -60,18 +60,18 @@ writeBase64aux (FILE *in, FILE *out, int crlf)
                     * everything down and push the last character back.
                     */
                    if (i == cc - 1) {
                     * everything down and push the last character back.
                     */
                    if (i == cc - 1) {
-                       /*
+                       /*
                         * If we're at the end of the input, there might be
                         * more room in inbuf; if so, add it there.  Otherwise
                         * push it back to the input.
                         */
                         * If we're at the end of the input, there might be
                         * more room in inbuf; if so, add it there.  Otherwise
                         * push it back to the input.
                         */
-                       if (cc < sizeof(inbuf))
+                       if (cc < sizeof(inbuf))
                            inbuf[cc++] = '\n';
                        else
                            ungetc('\n', in);
                        skipnl = true;
                    } else {
                            inbuf[cc++] = '\n';
                        else
                            ungetc('\n', in);
                        skipnl = true;
                    } else {
-                       /* This only works as long as sizeof(inbuf) == 3 */
+                       /* This only works as long as sizeof(inbuf) == 3 */
                        ungetc(inbuf[cc - 1], in);
                        if (cc == 3 && i == 0)
                            inbuf[2] = inbuf[1];
                        ungetc(inbuf[cc - 1], in);
                        if (cc == 3 && i == 0)
                            inbuf[2] = inbuf[1];
@@ -244,20 +244,16 @@ 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
  * 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
 decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
-             int skip_crs, unsigned char *digest) {
+             int skip_crs)
+{
     const char *cp = encoded;
     int bitno, skip;
     uint32_t bits;
     /* Size the decoded string very conservatively. */
     charstring_t decoded_c = charstring_create (strlen (encoded));
     const char *cp = encoded;
     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;
 
     bitno = 18;
     bits = 0L;
@@ -290,22 +286,16 @@ test_end:
                     if (! skip_crs  ||  b != '\r') {
                         charstring_push_back (decoded_c, b);
                     }
                     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 (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 (skip < 1) {
                             b = bits & 0xff;
                             if (! skip_crs  ||  b != '\r') {
                                 charstring_push_back (decoded_c, b);
                             }
-                            if (digest)
-                                MD5Update (&mdContext, (unsigned char *) &b, 1);
                         }
                     }
 
                         }
                     }
 
@@ -337,10 +327,6 @@ test_end:
     *len = charstring_bytes (decoded_c);
     charstring_free (decoded_c);
 
     *len = charstring_bytes (decoded_c);
     charstring_free (decoded_c);
 
-    if (digest) {
-        MD5Final (digest, &mdContext);
-    }
-
     return OK;
 }
 
     return OK;
 }
 
@@ -351,7 +337,8 @@ test_end:
  * is allocated by the function and must be freed by the caller.
  */
 void
  * 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;
     /* Start with a charstring capacity that's arbitrarily larger than len. */
     const charstring_t tmp = charstring_create (2 * len);
     const unsigned char *cp = input;