]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
move base64 to common code
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Nov 2010 19:51:46 +0000 (19:51 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 25 Nov 2010 19:51:46 +0000 (19:51 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10631 d7cf8633-e32d-0410-b094-e92efae38249

common.c
common.h
crypto.c

index 71c059aca7d739bb5452ce701c45dd432e51412f..11a350bfc2dba30daa9d4614657f0e9d873e7fb4 100644 (file)
--- a/common.c
+++ b/common.c
@@ -2260,3 +2260,34 @@ char **XPM_DecodeString(const char *in)
 
        return tokens;
 }
+
+static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static void base64_3to4(const unsigned char *in, unsigned char *out, int bytes)
+{
+       unsigned char i0 = (bytes > 0) ? in[0] : 0;
+       unsigned char i1 = (bytes > 1) ? in[1] : 0;
+       unsigned char i2 = (bytes > 2) ? in[2] : 0;
+       unsigned char o0 = base64[i0 >> 2];
+       unsigned char o1 = base64[((i0 << 4) | (i1 >> 4)) & 077];
+       unsigned char o2 = base64[((i1 << 2) | (i2 >> 6)) & 077];
+       unsigned char o3 = base64[i2 & 077];
+       out[0] = (bytes > 0) ? o0 : '?';
+       out[1] = (bytes > 0) ? o1 : '?';
+       out[2] = (bytes > 1) ? o2 : '=';
+       out[3] = (bytes > 2) ? o3 : '=';
+}
+
+size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen)
+{
+       size_t blocks, i;
+       // expand the out-buffer
+       blocks = (buflen + 2) / 3;
+       if(blocks*4 > outbuflen)
+               return 0;
+       for(i = blocks; i > 0; )
+       {
+               --i;
+               base64_3to4(buf + 3*i, buf + 4*i, buflen - 3*i);
+       }
+       return blocks * 4;
+}
index a5565ac76f050cdf72d9aad1f497058550b7f24f..f3516c5da03ce7d4241892f1bb40a71a9b096984 100644 (file)
--- a/common.h
+++ b/common.h
@@ -359,5 +359,7 @@ void FindFraction(double val, int *num, int *denom, int denomMax);
 // decodes XPM file to XPM array (as if #include'd)
 char **XPM_DecodeString(const char *in);
 
+size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen);
+
 #endif
 
index fa2ea67cde6db099aed949d0545368dd359658f8..c261d490253e23313412b9ed8e42aca53fa387a4 100644 (file)
--- a/crypto.c
+++ b/crypto.c
@@ -354,37 +354,6 @@ static size_t Crypto_LoadFile(const char *path, char *buf, size_t nmax)
        return (size_t) n;
 }
 
-static const char base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static void base64_3to4(const unsigned char *in, unsigned char *out, int bytes)
-{
-       unsigned char i0 = (bytes > 0) ? in[0] : 0;
-       unsigned char i1 = (bytes > 1) ? in[1] : 0;
-       unsigned char i2 = (bytes > 2) ? in[2] : 0;
-       unsigned char o0 = base64[i0 >> 2];
-       unsigned char o1 = base64[((i0 << 4) | (i1 >> 4)) & 077];
-       unsigned char o2 = base64[((i1 << 2) | (i2 >> 6)) & 077];
-       unsigned char o3 = base64[i2 & 077];
-       out[0] = (bytes > 0) ? o0 : '?';
-       out[1] = (bytes > 0) ? o1 : '?';
-       out[2] = (bytes > 1) ? o2 : '=';
-       out[3] = (bytes > 2) ? o3 : '=';
-}
-
-size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen)
-{
-       size_t blocks, i;
-       // expand the out-buffer
-       blocks = (buflen + 2) / 3;
-       if(blocks*4 > outbuflen)
-               return 0;
-       for(i = blocks; i > 0; )
-       {
-               --i;
-               base64_3to4(buf + 3*i, buf + 4*i, buflen - 3*i);
-       }
-       return blocks * 4;
-}
-
 static qboolean PutWithNul(char **data, size_t *len, const char *str)
 {
        // invariant: data points to insertion point