From 7a968ee77ac501d98900acf1e13c67aedce37d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Fri, 12 Jul 2013 21:13:22 +0200 Subject: [PATCH] Nuke the base64 code. It was wrong --- include/ucore/string.h | 4 ---- src/base64_dec.c | 52 ------------------------------------------ src/base64_enc.c | 43 ---------------------------------- test/test_runner.c | 2 +- 4 files changed, 1 insertion(+), 100 deletions(-) delete mode 100644 src/base64_dec.c delete mode 100644 src/base64_enc.c diff --git a/include/ucore/string.h b/include/ucore/string.h index 56eaf73..9b09103 100644 --- a/include/ucore/string.h +++ b/include/ucore/string.h @@ -9,10 +9,6 @@ extern "C" { #endif -size_t -uc_base64_enc(const unsigned char *data,size_t len,unsigned char *result); -size_t -uc_base64_dec(const unsigned char *data, size_t len, unsigned char *result); char* uc_hex_encode(const uint8_t *in, size_t len, char *out); diff --git a/src/base64_dec.c b/src/base64_dec.c deleted file mode 100644 index 5ac2e98..0000000 --- a/src/base64_dec.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include "ucore/string.h" - -static const uint8_t basecode[128] = -{ - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 62, 0xff, 0xff, 0xff, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0xff, 0xff, 0xff, 0xff, 0xff -}; - -#define deccode(c) ((c > 127) ? 0xff : basecode[(c)]) - -size_t -uc_base64_dec(const unsigned char *data, size_t len, unsigned char *result) -{ - size_t i = 0, j = 0, pad; - uint8_t c[4]; - - while ((i + 3) < len) { - - pad = 0; - c[0] = deccode(data[i ]); pad += (c[0] == 0xff); - c[1] = deccode(data[i+1]); pad += (c[1] == 0xff); - c[2] = deccode(data[i+2]); pad += (c[2] == 0xff); - c[3] = deccode(data[i+3]); pad += (c[3] == 0xff); - switch (pad) { - case 1: - result[j++] = (c[0] << 2) | ((c[1] & 0x30) >> 4); - result[j++] = ((c[1] & 0x0f) << 4) | ((c[2] & 0x3c) >> 2); - result[j] = (c[2] & 0x03) << 6; - break; - case 2: - result[j++] = (c[0] << 2) | ((c[1] & 0x30) >> 4); - result[j] = (c[1] & 0x0f) << 4; - break; - default: - result[j++] = (c[0] << 2) | ((c[1] & 0x30) >> 4); - result[j++] = ((c[1] & 0x0f) << 4) | ((c[2] & 0x3c) >> 2); - result[j++] = ((c[2] & 0x03) << 6) | (c[3] & 0x3f); - } - - i += 4; - } - - return j; -} - diff --git a/src/base64_enc.c b/src/base64_enc.c deleted file mode 100644 index bc8126e..0000000 --- a/src/base64_enc.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include -#include "ucore/string.h" - -static const char basecode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; -#define PAD '=' - -size_t -uc_base64_enc(const unsigned char *data,size_t len,unsigned char *result) -{ - - size_t i = 0, j = 0; - size_t pad; - - - while (i < len) { - pad = 3 - (len - i); - switch(pad) { - case 2: - result[j] = basecode[data[i]>>2]; - result[j+1] = basecode[(data[i] & 0x03) << 4]; - result[j+2] = PAD; - result[j+3] = PAD; - break; - case 3: - result[j ] = basecode[data[i]>>2]; - result[j+1] = basecode[((data[i] & 0x03) << 4) | ((data[i+1] & 0xf0) >> 4)]; - result[j+2] = basecode[(data[i+1] & 0x0f) << 2]; - result[j+3] = PAD; - break; - default: - result[j ] = basecode[data[i]>>2]; - result[j+1] = basecode[((data[i] & 0x03) << 4) | ((data[i+1] & 0xf0) >> 4)]; - result[j+2] = basecode[((data[i+1] & 0x0f) << 2) | ((data[i+2] & 0xc0) >> 6)]; - result[j+3] = basecode[data[i+2] & 0x3f]; - break; - } - j += 4; - i += 3; - } - - return j; -} diff --git a/test/test_runner.c b/test/test_runner.c index 2ab0db3..d3440c5 100644 --- a/test/test_runner.c +++ b/test/test_runner.c @@ -39,7 +39,7 @@ static suite_func suites[] = { timers_suite, mbuf_suite, human_bytesz_suite, - dbuf_suite + dbuf_suite, }; int