diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2006-06-25 16:07:01 +0200 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2006-06-25 16:07:01 +0200 |
commit | 7ed3199067034b4fda4055778e02274f83bcfcb8 (patch) | |
tree | 7dcb0b66645c578dda04cec69ea4f9c4c49bce75 /lib/misc.c | |
parent | df1694b9559d4abec748b0506b5f44e684d022a8 (diff) |
Moved Base64-related functions to a separate file and added decode funtions.
Diffstat (limited to 'lib/misc.c')
-rw-r--r-- | lib/misc.c | 44 |
1 files changed, 0 insertions, 44 deletions
@@ -83,50 +83,6 @@ char *add_cr(char *text) return ret; } -char *tobase64(const char *text) -{ - char *out; - int len; - - len = strlen(text); - out = g_malloc((len + 2) /* the == padding */ - / 3 /* every 3-byte block */ - * 4 /* becomes a 4-byte one */ - + 1); /* and of course, ASCIIZ! */ - - base64_encode_real(text, len, out, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); - - return out; -} - -void base64_encode_real(const unsigned char *in, int inlen, unsigned char *out, char *b64digits) -{ - for (; inlen >= 3; inlen -= 3) - { - *out++ = b64digits[in[0] >> 2]; - *out++ = b64digits[((in[0]<<4) & 0x30) | (in[1]>>4)]; - *out++ = b64digits[((in[1]<<2) & 0x3c) | (in[2]>>6)]; - *out++ = b64digits[in[2] & 0x3f]; - in += 3; - } - if (inlen > 0) - { - *out++ = b64digits[in[0] >> 2]; - if (inlen > 1) - { - *out++ = b64digits[((in[0]<<4) & 0x30) | (in[1]>>4)]; - *out++ = b64digits[((in[1]<<2) & 0x3c)]; - } - else - { - *out++ = b64digits[((in[0]<<4) & 0x30) | (in[1]>>4)]; - *out++ = b64digits[64]; - } - *out++ = b64digits[64]; - } - *out = '\0'; -} - char *normalize(const char *s) { static char buf[BUF_LEN]; |