summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorBryan Ischo <bryan@ischo.com>2008-08-13 13:27:47 +0000
committerBryan Ischo <bryan@ischo.com>2008-08-13 13:27:47 +0000
commit7fd73adff17c0511cf2c09da16d46d1a8e608866 (patch)
treefe09fe3dcdc6c68d9a17d80e64424c0e241c5247 /src/util.c
parent06fcf9839f35d1bbac18819886375b8232d73f35 (diff)
downloadceph-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.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 341c931..3c4f3c3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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);
+}