]> diplodocus.org Git - nmh/blobdiff - sbr/base64.c
fmt_addr.c: Move interface to own file.
[nmh] / sbr / base64.c
index cbd225dee062c60fa42ebb8415350bc17cb4f835..ef3aa32a0c8baf754c4a0df040a26bc2547103d0 100644 (file)
@@ -5,9 +5,10 @@
  * 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 "h/md5.h"
 #include <inttypes.h>
 
 static const char nib2b64[0x40+1] =
@@ -29,8 +30,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 +70,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 +79,7 @@ writeBase64aux (FILE *in, FILE *out, int crlf)
                        inbuf[++i] = '\n';
                    }
                } else {
-                   skipnl = 0;
+                   skipnl = false;
                }
            }
        }
@@ -248,9 +249,9 @@ static const unsigned char b642nib[0x80] = {
  */
 int
 decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
-             int skip_crs, unsigned char *digest) {
+             int skip_crs, unsigned char *digest)
+{
     const char *cp = encoded;
-    int self_delimiting = 0;
     int bitno, skip;
     uint32_t bits;
     /* Size the decoded string very conservatively. */
@@ -264,6 +265,7 @@ decodeBase64 (const char *encoded, unsigned char **decoded, size_t *len,
     bits = 0L;
     skip = 0;
 
+    bool self_delimiting = false;
     for (; *cp; ++cp) {
         switch (*cp) {
             unsigned char value;
@@ -318,7 +320,7 @@ test_end:
             case '=':
                 if (++skip <= 3)
                     goto test_end;
-                self_delimiting = 1;
+                self_delimiting = true;
                 break;
         }
     }
@@ -351,7 +353,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;