]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/base64.c
Fix header file includes.
[bacula/bacula] / bacula / src / lib / base64.c
index dbfcbd60bf46ed99e0ce3e669881a0b89dd809ae..19e83ce49d7820517cc72b0c0290f316d5e7ba06 100644 (file)
@@ -6,7 +6,7 @@
  *   Version $Id$
  */
 /*
-   Copyright (C) 2000-2005 Kern Sibbald
+   Copyright (C) 2000-2006 Kern Sibbald
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
 
 #include "bacula.h"
 
+/*
+ * If compatible is true, the bin_to_base64 routine will be compatible
+ * with what the rest of the world uses.  However, this would destroy
+ * existing database compatibility.
+ */
+const bool compatible = false;
+
 #ifdef TEST_MODE
 #include <glob.h>
 #endif
@@ -141,21 +148,33 @@ bin_to_base64(char *buf, char *bin, int len)
    for (i=0; i<len; ) {
       if (rem < 6) {
          reg <<= 8;
-         reg |= (int8_t)bin[i++];
+         if (compatible) {
+            reg |= (uint8_t)bin[i++];
+         } else {
+            reg |= (int8_t)bin[i++];
+         }
          rem += 8;
       }
       save = reg;
       reg >>= (rem - 6);
-      buf[j++] = base64_digits[reg & (uint32_t)0x3F];
+      buf[j++] = base64_digits[reg & 0x3F];
       reg = save;
       rem -= 6;
    }
    if (rem) {
+#ifdef OLDxxxx
       mask = 1;
       for (i=1; i<rem; i++) {
          mask = (mask << 1) | 1;
       }
-      buf[j++] = base64_digits[reg & mask];
+#else 
+      mask = (1 << rem) - 1;
+#endif
+      if (compatible) {
+         buf[j++] = base64_digits[(reg & mask) << 6 - rem];
+      } else {
+         buf[j++] = base64_digits[reg & mask];
+      }
    }
    buf[j] = 0;
    return j;