diff options
author | Bryan Ischo <bryan@ischo.com> | 2008-08-13 13:27:47 +0000 |
---|---|---|
committer | Bryan Ischo <bryan@ischo.com> | 2008-08-13 13:27:47 +0000 |
commit | 7fd73adff17c0511cf2c09da16d46d1a8e608866 (patch) | |
tree | fe09fe3dcdc6c68d9a17d80e64424c0e241c5247 /src/util.c | |
parent | 06fcf9839f35d1bbac18819886375b8232d73f35 (diff) | |
download | ceph-libs3-7fd73adff17c0511cf2c09da16d46d1a8e608866.tar.gz |
* Replaced openssl library with GnuTLS, libgcrypt, and hand-written base 64
encoding routine
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 38 |
1 files changed, 38 insertions, 0 deletions
@@ -171,3 +171,41 @@ uint64_t parseUnsignedInt(const char *str) return ret; } + + +int base64Encode(const unsigned char *in, int inLen, unsigned char *out) +{ + static const char *ENC = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + + unsigned char *original_out = out; + + while (inLen) { + // first 6 bits of char 1 + *out++ = ENC[*in >> 2]; + if (!--inLen) { + // last 2 bits of char 1, 4 bits of 0 + *out++ = ENC[(*in & 0x3) << 4]; + *out++ = '='; + *out++ = '='; + break; + } + // last 2 bits of char 1, first 4 bits of char 2 + *out++ = ENC[((*in & 0x3) << 4) | (*(in + 1) >> 4)]; + in++; + if (!--inLen) { + // last 4 bits of char 2, 2 bits of 0 + *out++ = ENC[(*in & 0xF) << 2]; + *out++ = '='; + break; + } + // last 4 bits of char 2, first 2 bits of char 3 + *out++ = ENC[((*in & 0xF) << 2) | (*(in + 1) >> 6)]; + in++; + // last 6 bits of char 3 + *out++ = ENC[*in & 0x3F]; + in++, inLen--; + } + + return (out - original_out); +} |