Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / mech_eap / util_base64.c
index 134b2cc..0ec1cdc 100644 (file)
@@ -124,9 +124,15 @@ base64Decode(const char *str, void *data)
     q = data;
     p = str;
 
-    while (*p && *p && (*p == '=' || strchr(base64_chars, *p))) {
-       unsigned int val = token_decode(p);
-       unsigned int marker = (val >> 24) & 0xff;
+    while (*p && (*p == '=' || strchr(base64_chars, *p) || isspace(*p))) {
+       unsigned int val; 
+       unsigned int marker; 
+       if (isspace(*p)) {
+            p++;
+            continue;
+        }
+        val = token_decode(p);
+        marker = (val >> 24) & 0xff;
        if (val == DECODE_ERROR)
            return -1;
        *q++ = (val >> 16) & 0xff;
@@ -135,8 +141,6 @@ base64Decode(const char *str, void *data)
        if (marker < 1)
            *q++ = val & 0xff;
        p += 4;
-       if (*p == '\n')
-           p++;
     }
     return q - (unsigned char *) data;
 }
@@ -144,15 +148,18 @@ base64Decode(const char *str, void *data)
 int
 base64Valid(const char *str)
 {
-    const char *p;
+    const char *p = str;
     int valid = 1;
 
-    for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
+    while (*p && *p && (*p == '=' || strchr(base64_chars, *p))) {
        unsigned int val = token_decode(p);
        if (val == DECODE_ERROR) {
             valid = 0;
            break;
         }
+       p += 4;
+       if (*p == '\n')
+           p++;
     }
     return valid;
 }