Fixes for Heimdal (macOS) builds from Stefan.
[mech_eap.git] / mech_eap / util_base64.c
index 5d5241d..0ec1cdc 100644 (file)
@@ -122,9 +122,17 @@ base64Decode(const char *str, void *data)
     unsigned char *q;
 
     q = data;
-    for (p = str; *p && (*p == '=' || strchr(base64_chars, *p)); p += 4) {
-       unsigned int val = token_decode(p);
-       unsigned int marker = (val >> 24) & 0xff;
+    p = str;
+
+    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;
@@ -132,6 +140,7 @@ base64Decode(const char *str, void *data)
            *q++ = (val >> 8) & 0xff;
        if (marker < 1)
            *q++ = val & 0xff;
+       p += 4;
     }
     return q - (unsigned char *) data;
 }
@@ -139,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;
 }