OSDN Git Service

implement base64decoder_t.
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 26 Feb 2012 09:54:06 +0000 (09:54 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 26 Feb 2012 09:54:06 +0000 (09:54 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@394 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/coding/base64decoder.c [new file with mode: 0644]
src/coding/base64decoder.h [new file with mode: 0644]
src/coding/test_base64decoder.c [new file with mode: 0644]

diff --git a/src/coding/base64decoder.c b/src/coding/base64decoder.c
new file mode 100644 (file)
index 0000000..1d48ff6
--- /dev/null
@@ -0,0 +1,145 @@
+/*
+ * base64decoder.c
+ *
+ * Copyright (c) 2012 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+#include    "base64decoder.h"
+
+#include       <basic.h>
+#include       <bstdio.h>
+
+#ifdef BCHAN_CONFIG_DEBUG
+# define DP(arg) printf arg
+# define DP_ER(msg, err) printf("%s (%d/%x)\n", msg, err>>16, err)
+#else
+# define DP(arg) /**/
+# define DP_ER(msg, err) /**/
+#endif
+
+LOCAL W base64decoder_convertchar(UB ch)
+{
+       if (('A' <= ch)&&(ch <= 'Z')) {
+               return ch - 'A' + 0;
+       }
+       if (('a' <= ch)&&(ch <= 'z')) {
+               return ch - 'a' + 26;
+       }
+       if (('0' <= ch)&&(ch <= '9')) {
+               return ch - '0' + 52;
+       }
+       if (ch == '+') {
+               return 62;
+       }
+       if (ch == '/') {
+               return 63;
+       }
+       if (ch == '=') {
+               return -2;
+       }
+       return -1;
+}
+
+EXPORT W base64decoder_inputchar(base64decoder_t *decoder, UB ch, UB **result, W *result_len)
+{
+       W num = base64decoder_convertchar(ch);
+
+       if (num == -1) {
+               return -1; /* TODO: error value */
+       }
+
+       *result = NULL;
+       *result_len = 0;
+
+       switch (decoder->state) {
+       case BASE64ENCODER_STATE_FIRSTCHAR:
+               if (num == -2) { /* PAD */
+                       return -1;
+               }
+               decoder->buffer[0] = num << 2;
+               decoder->state = BASE64ENCODER_STATE_SECONDCHAR;
+               break;
+       case BASE64ENCODER_STATE_SECONDCHAR:
+               if (num == -2) { /* PAD */
+                       return -1;
+               }
+               decoder->buffer[0] |= (num >> 4);
+               decoder->buffer[1] = (num & 0xF) << 4;
+               decoder->state = BASE64ENCODER_STATE_THIRDCHAR;
+               break;
+       case BASE64ENCODER_STATE_THIRDCHAR:
+               if (num == -2) { /* PAD */
+                       *result = decoder->buffer;
+                       *result_len = 1;
+                       decoder->state = BASE64ENCODER_STATE_FORTHCHAR_PAD;
+               } else {
+                       decoder->buffer[1] |= (num >> 2);
+                       decoder->buffer[2] = (num & 0x3) << 6;
+                       decoder->state = BASE64ENCODER_STATE_FORTHCHAR;
+               }
+               break;
+       case BASE64ENCODER_STATE_FORTHCHAR:
+               if (num == -2) { /* PAD */
+                       *result = decoder->buffer;
+                       *result_len = 2;
+                       decoder->state = BASE64ENCODER_STATE_PAD;
+               } else {
+                       decoder->buffer[2] |= num;
+                       decoder->state = BASE64ENCODER_STATE_FIRSTCHAR;
+                       *result = decoder->buffer;
+                       *result_len = 3;
+               }
+               break;
+       case BASE64ENCODER_STATE_FORTHCHAR_PAD:
+               if (num != -2) { /* PAD */
+                       return -1;
+               }
+               decoder->state = BASE64ENCODER_STATE_PAD;
+               break;
+       case BASE64ENCODER_STATE_PAD:
+               return -1;
+       }
+
+       return 0;
+}
+
+EXPORT VOID base64decoder_endinput(base64decoder_t *decoder, UB **result, W *result_len)
+{
+       *result = NULL;
+       *result_len = 0;
+       return;
+}
+
+EXPORT VOID base64decoder_clear(base64decoder_t *decoder)
+{
+       decoder->state = BASE64ENCODER_STATE_FIRSTCHAR;
+}
+
+EXPORT VOID base64decoder_initialize(base64decoder_t *decoder)
+{
+       decoder->state = BASE64ENCODER_STATE_FIRSTCHAR;
+}
+
+EXPORT VOID base64decoder_finalize(base64decoder_t *decoder)
+{
+}
diff --git a/src/coding/base64decoder.h b/src/coding/base64decoder.h
new file mode 100644 (file)
index 0000000..3c67c98
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * base64decoder.h
+ *
+ * Copyright (c) 2012 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+/* Vendor name: */
+/* Functionality name: base64decoder */
+/* Detail name: */
+
+#include    <basic.h>
+
+/* rfc3548 3 Base 64 Encoding */
+
+#ifndef __BASE64DECODER_H__
+#define __BASE64DECODER_H__
+
+/* Functionality name: base64decoder */
+/* Detail name: */
+struct base64decoder_t_ {
+       enum {
+               BASE64ENCODER_STATE_FIRSTCHAR,
+               BASE64ENCODER_STATE_SECONDCHAR,
+               BASE64ENCODER_STATE_THIRDCHAR,
+               BASE64ENCODER_STATE_FORTHCHAR,
+               BASE64ENCODER_STATE_FORTHCHAR_PAD,
+               BASE64ENCODER_STATE_PAD,
+       } state;
+       UB buffer[3];
+};
+typedef struct base64decoder_t_ base64decoder_t;
+
+IMPORT VOID base64decoder_initialize(base64decoder_t *decoder);
+IMPORT VOID base64decoder_finalize(base64decoder_t *decoder);
+IMPORT W base64decoder_inputchar(base64decoder_t *decoder, UB ch, UB **result, W *result_len);
+IMPORT VOID base64decoder_endinput(base64decoder_t *decoder, UB **result, W *result_len);
+IMPORT VOID base64decoder_clear(base64decoder_t *decoder);
+
+#endif
diff --git a/src/coding/test_base64decoder.c b/src/coding/test_base64decoder.c
new file mode 100644 (file)
index 0000000..d2f028e
--- /dev/null
@@ -0,0 +1,440 @@
+/*
+ * test_base64decoder.c
+ *
+ * Copyright (c) 2012 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+#include    "test_coding.h"
+
+#include    "base64decoder.h"
+
+#include    <btron/btron.h>
+#include       <tcode.h>
+#include    <bstdio.h>
+#include    <bstdlib.h>
+#include    <bstring.h>
+#include    <errcode.h>
+
+#include    <unittest_driver.h>
+
+struct testbase64decoder_result_t_ {
+       UB *str;
+       W len;
+};
+typedef struct testbase64decoder_result_t_ testbase64decoder_result_t;
+
+LOCAL W testbase64decoder_result_append(testbase64decoder_result_t *testresult, UB *apd, W apd_len)
+{
+       UB *str;
+
+       str = realloc(testresult->str, testresult->len + apd_len + 1);
+       if (str == NULL) {
+               return -1;
+       }
+       testresult->str = str;
+
+       memcpy(testresult->str + testresult->len, apd, apd_len);
+       testresult->len += apd_len;
+       testresult->str[testresult->len] = '\0';
+
+       return 0;
+}
+
+LOCAL W testbase64decoder_result_inputresult(testbase64decoder_result_t *testresult, UB *apd, W apd_len)
+{
+       return testbase64decoder_result_append(testresult, apd, apd_len);
+}
+
+LOCAL Bool testbase64decoder_result_compaire(testbase64decoder_result_t *testresult, UB *expected, W expected_len)
+{
+       W i;
+
+       if (testresult->len != expected_len) {
+               printf("length: result = %d, expected = %d\n", testresult->len, expected_len);
+               return False;
+       }
+       for (i = 0; i < expected_len; i++) {
+               if (testresult->str[i] != expected[i]) {
+                       printf("content: %d: result = %02x, expected = %02x\n", i, testresult->str[i], expected[i]);
+                       return False;
+               }
+       }
+       return True;
+}
+
+LOCAL W testbase64decoder_result_initialize(testbase64decoder_result_t *testresult)
+{
+       testresult->str = malloc(sizeof(UB));
+       if (testresult->str == NULL) {
+               return -1;
+       }
+       testresult->str[0] = '\0';
+       testresult->len = 0;
+       return 0;
+}
+
+LOCAL VOID testbase64decoder_result_finalize(testbase64decoder_result_t *testresult)
+{
+       free(testresult->str);
+}
+
+LOCAL UNITTEST_RESULT test_base64decoder_common(UB *test, W test_len, UB *expected, W expected_len)
+{
+       testbase64decoder_result_t testresult;
+       base64decoder_t decoder;
+       W i, err, result_len;
+       UB *result;
+       UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+       Bool ok;
+
+       base64decoder_initialize(&decoder);
+       err = testbase64decoder_result_initialize(&testresult);
+       if (err < 0) {
+               base64decoder_finalize(&decoder);
+               return UNITTEST_RESULT_FAIL;
+       }
+
+       for (i = 0; i < test_len; i++) {
+               if (test[i] == '\n') {
+                       continue;
+               }
+               err = base64decoder_inputchar(&decoder, test[i], &result, &result_len);
+               if (err < 0) {
+                       ret = UNITTEST_RESULT_FAIL;
+               }
+               err = testbase64decoder_result_inputresult(&testresult, result, result_len);
+               if (err < 0) {
+                       ret = UNITTEST_RESULT_FAIL;
+               }
+       }
+       base64decoder_endinput(&decoder, &result, &result_len);
+       err = testbase64decoder_result_inputresult(&testresult, result, result_len);
+       if (err < 0) {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       ok = testbase64decoder_result_compaire(&testresult, expected, expected_len);
+       if (ok == False) {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       testbase64decoder_result_finalize(&testresult);
+       base64decoder_finalize(&decoder);
+
+       return ret;
+}
+
+LOCAL UB test_base64decoder_testdata01_raw[] = {
+       0x61, 0x62, 0x63, 0x64, 0x65, 0x67, 0x68, 0x0a, 
+       0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
+};
+LOCAL UB test_base64decoder_testdata01_encoded[] = {"YWJjZGVnaAppamtsbW5v"};
+LOCAL UB test_base64decoder_testdata02_raw[] = {
+       0x61, 0x62, 0x63, 0x64, 0x65, 0x67, 0x68, 0x0a, 
+       0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 
+};
+LOCAL UB test_base64decoder_testdata02_encoded[] = {"YWJjZGVnaAppamtsbW5vcA=="};
+LOCAL UB test_base64decoder_testdata03_raw[] = {
+       0x61, 0x62, 0x63, 0x64, 0x65, 0x67, 0x68, 0x0a, 
+       0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 
+       0x71,
+};
+LOCAL UB test_base64decoder_testdata03_encoded[] = {"YWJjZGVnaAppamtsbW5vcHE="};
+LOCAL UB test_base64decoder_testdata04_raw[] = {
+       0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x1f, 0x00, 
+       0x1f, 0x00, 0xf7, 0xff, 0x00, 0x2d, 0x32, 0x35, 
+       0x31, 0x2d, 0x2d, 0x3e, 0x3a, 0x39, 0x27, 0x37, 
+       0x40, 0x1c, 0x43, 0x38, 0x1e, 0x6b, 0x37, 0x28, 
+       0x47, 0x3b, 0x1c, 0x53, 0x6f, 0x1b, 0x50, 0x6c, 
+       0x1f, 0x79, 0x41, 0x2d, 0x4f, 0x45, 0x39, 0x46, 
+       0x45, 0x30, 0x4f, 0x5f, 0x3d, 0x50, 0x5a, 0x26, 
+       0x7d, 0x46, 0x3c, 0x7e, 0x51, 0x37, 0x6e, 0x51, 
+       0x41, 0x3f, 0x3f, 0x5b, 0x4f, 0x22, 0x52, 0x4c, 
+       0x37, 0x5f, 0x51, 0x24, 0x4a, 0x45, 0x3f, 0x63, 
+       0x5a, 0x39, 0x7d, 0x6a, 0x24, 0x48, 0x48, 0x48, 
+       0x4b, 0x56, 0x54, 0x50, 0x4c, 0x4b, 0x55, 0x53, 
+       0x53, 0x5f, 0x5c, 0x5b, 0x56, 0x57, 0x4f, 0x51, 
+       0x5b, 0x60, 0x46, 0x5d, 0x68, 0x40, 0x6d, 0x5f, 
+       0x5c, 0x71, 0x7c, 0x68, 0x68, 0x68, 0x78, 0x77, 
+       0x75, 0x62, 0x71, 0x7a, 0x75, 0x6b, 0x4b, 0x2e, 
+       0x6a, 0x86, 0x72, 0x7b, 0x80, 0x1d, 0x85, 0x46, 
+       0x1f, 0x87, 0x48, 0x27, 0x81, 0x49, 0x22, 0x91, 
+       0x4f, 0x27, 0x94, 0x53, 0x25, 0x99, 0x56, 0x2b, 
+       0x9a, 0x59, 0x31, 0x80, 0x4e, 0x3a, 0x83, 0x55, 
+       0x37, 0x88, 0x55, 0x33, 0x99, 0x5c, 0x36, 0x9f, 
+       0x62, 0x24, 0xa2, 0x5a, 0x2b, 0xa2, 0x5d, 0x32, 
+       0xa4, 0x63, 0x3b, 0xa7, 0x69, 0x2e, 0xa5, 0x61, 
+       0x44, 0x89, 0x5d, 0x4f, 0x8c, 0x7b, 0x46, 0x9a, 
+       0x68, 0x52, 0x97, 0x6b, 0x5d, 0x9b, 0x74, 0x54, 
+       0x9e, 0x71, 0x4b, 0x90, 0x6f, 0x44, 0xa9, 0x6f, 
+       0x47, 0xac, 0x72, 0x52, 0xa6, 0x74, 0x5a, 0xaf, 
+       0x7d, 0x54, 0xab, 0x78, 0x4a, 0xb1, 0x77, 0x62, 
+       0x9c, 0x77, 0x64, 0x9e, 0x79, 0x67, 0xa0, 0x7d, 
+       0x3e, 0x81, 0xa6, 0x59, 0xab, 0x95, 0x5f, 0xa5, 
+       0x90, 0x55, 0xa4, 0x8e, 0x6c, 0x8f, 0x84, 0x6d, 
+       0x8d, 0x9e, 0x73, 0x8a, 0x82, 0x69, 0xac, 0x84, 
+       0x66, 0xab, 0x82, 0x62, 0xb4, 0x84, 0x65, 0xbb, 
+       0x8a, 0x6b, 0xb4, 0x89, 0x69, 0xb5, 0x88, 0x75, 
+       0xa8, 0x88, 0x7e, 0xae, 0x90, 0x73, 0xb2, 0x8c, 
+       0x7c, 0xb4, 0x92, 0x71, 0xbd, 0x91, 0x67, 0xa8, 
+       0x96, 0x78, 0xb5, 0xa3, 0x6c, 0xba, 0xa5, 0x79, 
+       0xc1, 0x97, 0x87, 0x75, 0x34, 0x80, 0x7c, 0x7b, 
+       0xbb, 0x4c, 0x4e, 0xb7, 0x46, 0x47, 0xba, 0x5b, 
+       0x5b, 0xba, 0x5f, 0x60, 0xbd, 0x6f, 0x71, 0xbd, 
+       0x72, 0x73, 0xbd, 0x62, 0x63, 0xc2, 0x58, 0x5a, 
+       0xc5, 0x5e, 0x60, 0xc3, 0x68, 0x68, 0xc8, 0x6f, 
+       0x71, 0xc9, 0x77, 0x77, 0x8f, 0x86, 0x36, 0xac, 
+       0x96, 0x3d, 0xb6, 0x9d, 0x35, 0x9c, 0x8a, 0x41, 
+       0x80, 0x88, 0x7e, 0x9f, 0x96, 0x69, 0xbb, 0xac, 
+       0x65, 0xd9, 0xa7, 0x2f, 0xde, 0xb5, 0x53, 0xd9, 
+       0xb0, 0x5c, 0xd8, 0xaa, 0x57, 0xd9, 0xb5, 0x66, 
+       0xdb, 0xbc, 0x7b, 0xe7, 0xb8, 0x47, 0xe4, 0xb8, 
+       0x5c, 0xe5, 0xb8, 0x64, 0xe7, 0xca, 0x4c, 0xee, 
+       0xd2, 0x6f, 0x8a, 0x87, 0x87, 0x91, 0x8d, 0x8a, 
+       0x9a, 0x97, 0x97, 0x80, 0x9b, 0x8b, 0x83, 0xb3, 
+       0x95, 0x87, 0xb9, 0x9a, 0x8f, 0xac, 0x91, 0x83, 
+       0xaf, 0xa2, 0x8f, 0xbe, 0xa1, 0x9d, 0xa3, 0xa0, 
+       0x91, 0xbf, 0xa3, 0x99, 0xac, 0xb4, 0xa0, 0x9e, 
+       0x9d, 0xa7, 0xa4, 0x95, 0xb2, 0xac, 0x9f, 0xa7, 
+       0xa5, 0xa5, 0xb0, 0xaf, 0xaf, 0xbb, 0xb9, 0xb9, 
+       0xa4, 0xb2, 0xad, 0x82, 0xc5, 0x9e, 0x8a, 0xc8, 
+       0xa4, 0x8d, 0xc6, 0xb7, 0x91, 0xc5, 0xa6, 0x92, 
+       0xce, 0xac, 0x9c, 0xc1, 0xaa, 0x99, 0xcb, 0xae, 
+       0x95, 0xc5, 0xa9, 0x9f, 0xcd, 0xb2, 0x94, 0xd0, 
+       0xae, 0x97, 0xd2, 0xb0, 0x9e, 0xd4, 0xb5, 0xa2, 
+       0xc5, 0xaf, 0xa7, 0xca, 0xb6, 0xab, 0xd5, 0xbc, 
+       0xab, 0xd9, 0xbf, 0xa7, 0xd4, 0xba, 0xb2, 0xd2, 
+       0xbf, 0x98, 0xd1, 0xc1, 0xa9, 0xc6, 0xd6, 0xaf, 
+       0xdb, 0xc2, 0xb5, 0xd3, 0xc1, 0xb5, 0xdc, 0xc6, 
+       0xbc, 0xdc, 0xc9, 0xba, 0xd8, 0xc8, 0xad, 0xcb, 
+       0xc3, 0xbd, 0xe1, 0xcd, 0xc9, 0x87, 0x87, 0xcd, 
+       0x8f, 0x90, 0xce, 0x93, 0x93, 0xcf, 0x9b, 0x9c, 
+       0xd5, 0x8a, 0x8c, 0xd4, 0x84, 0x86, 0xd6, 0x94, 
+       0x95, 0xd3, 0x9a, 0x9b, 0xd9, 0x98, 0x99, 0xca, 
+       0x9f, 0xa0, 0xd7, 0x9f, 0xa0, 0xd9, 0xbb, 0x84, 
+       0xdc, 0xad, 0xae, 0xd7, 0xa6, 0xa7, 0xd5, 0xb3, 
+       0xb3, 0xcb, 0xb0, 0xaa, 0xe4, 0xbc, 0xbd, 0xdc, 
+       0xbf, 0xc0, 0xd8, 0xc3, 0x85, 0xd9, 0xc5, 0x98, 
+       0xc0, 0xc0, 0xb4, 0xd9, 0xc8, 0xa9, 0xe9, 0xc8, 
+       0x8c, 0xef, 0xcf, 0x94, 0xf3, 0xd2, 0x88, 0xf7, 
+       0xd9, 0x97, 0xf6, 0xcf, 0x83, 0xeb, 0xda, 0xaa, 
+       0xf5, 0xdc, 0xa5, 0xe7, 0xdc, 0xb2, 0xf0, 0xe3, 
+       0xad, 0xc8, 0xc6, 0xc7, 0xcf, 0xce, 0xce, 0xc1, 
+       0xd8, 0xcc, 0xc7, 0xde, 0xd0, 0xc9, 0xdd, 0xd1, 
+       0xcd, 0xd0, 0xd1, 0xde, 0xdd, 0xdd, 0xd5, 0xd3, 
+       0xd3, 0xd9, 0xd5, 0xc9, 0xc2, 0xe1, 0xcf, 0xc4, 
+       0xe4, 0xd2, 0xcb, 0xe4, 0xd5, 0xcf, 0xe9, 0xda, 
+       0xc8, 0xe0, 0xd9, 0xd3, 0xea, 0xdd, 0xd9, 0xe1, 
+       0xde, 0xd6, 0xe4, 0xdc, 0xdc, 0xe5, 0xe1, 0xdc, 
+       0xeb, 0xe2, 0xdf, 0xe6, 0xea, 0xea, 0xc4, 0xc5, 
+       0xe9, 0xcd, 0xcd, 0xec, 0xd8, 0xd7, 0xf0, 0xcc, 
+       0xcd, 0xf1, 0xd8, 0xd8, 0xe7, 0xe2, 0xcd, 0xeb, 
+       0xe5, 0xd8, 0xf6, 0xea, 0xc6, 0xf8, 0xee, 0xd8, 
+       0xfb, 0xf1, 0xd2, 0xf9, 0xf3, 0xdd, 0xe4, 0xe4, 
+       0xe4, 0xe1, 0xea, 0xe6, 0xe4, 0xef, 0xe9, 0xeb, 
+       0xe5, 0xe5, 0xeb, 0xec, 0xeb, 0xef, 0xed, 0xe5, 
+       0xe4, 0xf2, 0xea, 0xe5, 0xf1, 0xea, 0xed, 0xf6, 
+       0xf1, 0xef, 0xf8, 0xf3, 0xf2, 0xef, 0xed, 0xf3, 
+       0xee, 0xe4, 0xf1, 0xef, 0xf0, 0xf3, 0xf1, 0xec, 
+       0xfb, 0xf7, 0xe7, 0xf4, 0xf4, 0xf3, 0xfa, 0xf6, 
+       0xf5, 0xfc, 0xfb, 0xf6, 0xfe, 0xfe, 0xfe, 0xf4, 
+       0xf9, 0xf7, 0xe5, 0xee, 0xf3, 0x21, 0xf9, 0x04, 
+       0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 
+       0x00, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00, 0x08, 
+       0xfe, 0x00, 0xfb, 0x09, 0x1c, 0xc8, 0xc9, 0x5a, 
+       0x3c, 0x4e, 0xa1, 0x06, 0x2a, 0x14, 0x68, 0xca, 
+       0x52, 0x3c, 0x6c, 0x9c, 0x16, 0x4a, 0xc4, 0x46, 
+       0x83, 0x53, 0x11, 0x1a, 0xac, 0x24, 0x0e, 0xb4, 
+       0x46, 0xe3, 0x46, 0x27, 0x1a, 0xd6, 0x34, 0xf6, 
+       0xa3, 0x67, 0xad, 0x13, 0x8e, 0x4e, 0x53, 0x4c, 
+       0x89, 0x1c, 0xc8, 0x6a, 0x4a, 0xa7, 0x1b, 0x96, 
+       0xac, 0xcd, 0x93, 0x88, 0xea, 0x86, 0x35, 0x2f, 
+       0x35, 0x70, 0xa8, 0x5c, 0xd9, 0x0f, 0x15, 0x8e, 
+       0x1a, 0x5e, 0xac, 0xdd, 0x48, 0xb8, 0x70, 0x52, 
+       0x0d, 0x6d, 0x93, 0xa6, 0xb0, 0xe2, 0xc7, 0xb3, 
+       0x1f, 0x3f, 0x6b, 0x53, 0xbc, 0x68, 0xc3, 0xe1, 
+       0x45, 0x21, 0x3d, 0x4b, 0xa6, 0xa6, 0xdc, 0x68, 
+       0x81, 0xaa, 0xa9, 0xc0, 0x7c, 0xe9, 0x58, 0xd5, 
+       0xb0, 0x21, 0x25, 0x14, 0xa7, 0x99, 0xfd, 0xbc, 
+       0xb5, 0x48, 0x95, 0x8a, 0x48, 0x57, 0xaf, 0xfd, 
+       0xd2, 0xf5, 0x29, 0xc7, 0xaa, 0x08, 0xaa, 0x54, 
+       0x2d, 0xb4, 0x09, 0x8c, 0xd7, 0xc2, 0x4b, 0x10, 
+       0x22, 0xf4, 0x04, 0xfe, 0x2b, 0x25, 0x31, 0xdf, 
+       0x32, 0x64, 0xea, 0xf2, 0xcd, 0xf5, 0x27, 0x25, 
+       0xc8, 0xa4, 0x16, 0xde, 0xfa, 0x69, 0x13, 0x25, 
+       0xaa, 0xca, 0x8c, 0x54, 0x03, 0x4b, 0x99, 0xf8, 
+       0xa7, 0x90, 0x9f, 0x9f, 0x5f, 0xca, 0xfc, 0x2c, 
+       0xeb, 0x63, 0xae, 0x9f, 0x35, 0xb2, 0xa2, 0x40, 
+       0x71, 0x4b, 0xc5, 0xc2, 0x9a, 0xa8, 0x21, 0xf3, 
+       0xd6, 0x3d, 0xea, 0xe6, 0xc4, 0x84, 0xa2, 0x77, 
+       0xcc, 0xd6, 0x39, 0x62, 0xf4, 0x86, 0x5a, 0x3f, 
+       0x3f, 0x73, 0xdc, 0x2c, 0x53, 0xa7, 0x6f, 0xc8, 
+       0xa7, 0x6b, 0x2c, 0x42, 0xb5, 0x93, 0x51, 0x85, 
+       0x45, 0x15, 0x7d, 0x81, 0x04, 0x90, 0x58, 0xe0, 
+       0xe1, 0x43, 0xb4, 0x11, 0x7f, 0x30, 0x68, 0xb8, 
+       0x10, 0xec, 0x91, 0x9b, 0x2f, 0x17, 0xe0, 0xfe, 
+       0x94, 0x30, 0xa7, 0x65, 0x05, 0x15, 0x19, 0xde, 
+       0xac, 0x9d, 0xaa, 0x24, 0x44, 0xd5, 0x3b, 0x40, 
+       0x0b, 0x1a, 0x34, 0xc0, 0x70, 0x20, 0x04, 0x07, 
+       0x0c, 0x1b, 0x3a, 0x50, 0x08, 0x36, 0xa2, 0x8d, 
+       0x9c, 0x36, 0x15, 0x00, 0x72, 0x4f, 0x2a, 0x42, 
+       0x54, 0x12, 0xca, 0x33, 0x42, 0x54, 0xe1, 0xcd, 
+       0x0e, 0x99, 0x48, 0xc3, 0x01, 0x00, 0x00, 0x8c, 
+       0xa0, 0x01, 0x02, 0x26, 0x28, 0xb0, 0x40, 0x06, 
+       0x04, 0x18, 0x30, 0x47, 0x21, 0x3f, 0xc4, 0x41, 
+       0x01, 0x20, 0x90, 0xec, 0xa3, 0xc9, 0x0c, 0xda, 
+       0x60, 0x01, 0x04, 0x26, 0x28, 0x50, 0x81, 0x42, 
+       0x35, 0xcc, 0x04, 0x00, 0x00, 0x06, 0x60, 0x80, 
+       0xc1, 0xc0, 0x01, 0x19, 0x3c, 0xc1, 0x01, 0x01, 
+       0x0d, 0x30, 0x72, 0x85, 0x23, 0x23, 0x50, 0xe0, 
+       0xc8, 0x22, 0xeb, 0x64, 0x93, 0x42, 0x15, 0x2a, 
+       0x54, 0x12, 0x8f, 0x27, 0x98, 0x44, 0xe1, 0x09, 
+       0x24, 0x1a, 0x0c, 0x90, 0x81, 0x06, 0x1a, 0x90, 
+       0xf0, 0x84, 0x08, 0x91, 0x2c, 0xa0, 0x40, 0x06, 
+       0x86, 0xac, 0x52, 0xcf, 0x08, 0x16, 0xc0, 0x23, 
+       0xd0, 0x27, 0x50, 0x64, 0x82, 0x49, 0x3b, 0x84, 
+       0x40, 0xc1, 0x8d, 0x0f, 0x56, 0x4c, 0x33, 0xcd, 
+       0x22, 0x22, 0xb4, 0x89, 0x08, 0x2f, 0x7f, 0x34, 
+       0xa1, 0xc3, 0x16, 0x20, 0xe8, 0xf0, 0x89, 0x3e, 
+       0x7f, 0x2c, 0x32, 0x10, 0x16, 0x3b, 0x70, 0x83, 
+       0x45, 0x16, 0xd6, 0xa8, 0xe0, 0x43, 0x0c, 0x58, 
+       0xe8, 0x33, 0x10, 0x53, 0x02, 0x7d, 0xa3, 0x44, 
+       0x24, 0x94, 0x70, 0x71, 0x8a, 0x12, 0xdf, 0x28, 
+       0xe4, 0x4f, 0x16, 0x31, 0x08, 0xe1, 0x80, 0x2a, 
+       0xfd, 0xa4, 0x92, 0x08, 0x28, 0x3b, 0x7c, 0xa2, 
+       0x11, 0x29, 0x4b, 0xbc, 0x43, 0x0a, 0x17, 0xfa, 
+       0x74, 0x41, 0x89, 0x42, 0xa3, 0x74, 0x7a, 0x08, 
+       0xa6, 0xfd, 0x5c, 0x32, 0x08, 0x34, 0xfe, 0x2a, 
+       0x64, 0x21, 0x51, 0x36, 0x4a, 0x18, 0xd2, 0x4d, 
+       0x17, 0x5b, 0x6c, 0x43, 0x09, 0x13, 0xac, 0xf6, 
+       0x43, 0x88, 0x03, 0xd6, 0x0c, 0x92, 0x09, 0x53, 
+       0xaa, 0x38, 0x10, 0x43, 0x0f, 0x3d, 0x5c, 0xb2, 
+       0x50, 0x3b, 0xdb, 0x74, 0xf3, 0x0e, 0x37, 0xdc, 
+       0xbc, 0xf3, 0x8d, 0x34, 0xeb, 0x08, 0xe4, 0x09, 
+       0xb2, 0x39, 0x24, 0x30, 0xca, 0x40, 0xdc, 0x5c, 
+       0xe2, 0xcd, 0x15, 0x0e, 0xb0, 0x03, 0x97, 0x40, 
+       0xec, 0xc0, 0x60, 0x85, 0x37, 0x97, 0x5c, 0xa3, 
+       0x90, 0x37, 0x46, 0x1c, 0x71, 0x05, 0x0c, 0x47, 
+       0x60, 0x9a, 0x4e, 0x3e, 0x71, 0x9d, 0x83, 0x68, 
+       0x3a, 0xe7, 0x08, 0xe4, 0x4c, 0x0f, 0xe6, 0x22, 
+       0xd1, 0x43, 0x37, 0x9d, 0x79, 0x02, 0x43, 0x0f, 
+       0xd0, 0xf0, 0x5b, 0x8e, 0x1e, 0xbf, 0x9c, 0xa3, 
+       0x07, 0x1f, 0xc8, 0x18, 0xa3, 0x4c, 0x31, 0x78, 
+       0xa4, 0x53, 0x4f, 0x0e, 0x3c, 0x5c, 0x73, 0xc4, 
+       0x0b, 0x97, 0x20, 0xaa, 0xd0, 0x3b, 0x9f, 0x44, 
+       0x32, 0x48, 0x0e, 0xf2, 0x14, 0x93, 0x87, 0xc8, 
+       0xc9, 0xec, 0xa1, 0x07, 0x1e, 0xc7, 0xd0, 0xa1, 
+       0x07, 0x30, 0x39, 0x0c, 0x12, 0xc9, 0x27, 0xed, 
+       0x88, 0xa4, 0x8f, 0x15, 0x05, 0x3c, 0xb0, 0xed, 
+       0x31, 0x79, 0x10, 0x93, 0x87, 0x31, 0x76, 0xf0, 
+       0x01, 0x8c, 0x31, 0x78, 0xf8, 0x81, 0x8b, 0x2a, 
+       0x0f, 0x14, 0x60, 0x05, 0x67, 0x22, 0xf1, 0xd3, 
+       0x4d, 0x37, 0xfc, 0xd8, 0x63, 0xc7, 0x1d, 0xc8, 
+       0xe0, 0x71, 0x87, 0x30, 0x40, 0x0f, 0x83, 0x8b, 
+       0xd5, 0xfb, 0x7c, 0xd3, 0xcd, 0x3e, 0x22, 0x8d, 
+       0x43, 0x8e, 0x42, 0xfb, 0x98, 0xa3, 0x8b, 0x38, 
+       0xf0, 0x88, 0xd3, 0x4f, 0xd8, 0xf7, 0xd4, 0xa3, 
+       0x76, 0x53, 0xfb, 0xa4, 0xa1, 0x06, 0x39, 0xb1, 
+       0xcc, 0xd2, 0x8b, 0x2c, 0xb9, 0xd4, 0xf2, 0x0a, 
+       0x38, 0xbd, 0xdc, 0x12, 0x0b, 0x6c, 0x38, 0xb1, 
+       0xe4, 0x12, 0x4b, 0x38, 0x75, 0xf3, 0x3d, 0x0b, 
+       0x38, 0xbb, 0x28, 0x04, 0x8e, 0x18, 0x62, 0xcc, 
+       0x32, 0x46, 0x1a, 0x6b, 0x9c, 0xa1, 0xc6, 0x1a, 
+       0xad, 0xa0, 0x51, 0x86, 0x18, 0x61, 0xb4, 0x42, 
+       0xc6, 0x2e, 0x61, 0xdc, 0xc2, 0x86, 0x18, 0x6c, 
+       0x98, 0x31, 0x4b, 0x18, 0xb6, 0x28, 0x94, 0xcb, 
+       0x2e, 0xb4, 0xb4, 0xf2, 0x8a, 0x2b, 0xaf, 0xd0, 
+       0xe2, 0x8a, 0x2b, 0xc2, 0xac, 0xb1, 0x4b, 0x2d, 
+       0x65, 0xdc, 0x72, 0x8b, 0x38, 0x90, 0xab, 0x41, 
+       0x46, 0x2b, 0xbc, 0x90, 0x13, 0x46, 0xb5, 0x03, 
+       0x71, 0xcd, 0x8f, 0x3e, 0xc0, 0xef, 0xb3, 0x0f, 
+       0xf0, 0x67, 0x0b, 0xef, 0xce, 0x3d, 0xc6, 0xeb, 
+       0x73, 0xcf, 0x3b, 0x86, 0x86, 0x13, 0xba, 0x40, 
+       0x01, 0x01, 0x00, 0x3b,
+};
+LOCAL UB test_base64decoder_testdata04_encoded[] = {"R0lGODlhHwAfAPf/AC0yNTEtLT46OSc3QBxDOB5rNyhHOxxTbxtQbB95QS1P
+RTlGRTBPXz1QWiZ9Rjx+UTduUUE/P1tPIlJMN19RJEpFP2NaOX1qJEhISEtW
+VFBMS1VTU19cW1ZXT1FbYEZdaEBtX1xxfGhoaHh3dWJxenVrSy5qhnJ7gB2F
+Rh+HSCeBSSKRTyeUUyWZViuaWTGATjqDVTeIVTOZXDafYiSiWiuiXTKkYzun
+aS6lYUSJXU+Me0aaaFKXa12bdFSecUuQb0Spb0esclKmdFqvfVSreEqxd2Kc
+d2SeeWegfT6BplmrlV+lkFWkjmyPhG2NnnOKgmmshGargmK0hGW7imu0iWm1
+iHWoiH6ukHOyjHy0knG9kWeolni1o2y6pXnBl4d1NIB8e7tMTrdGR7pbW7pf
+YL1vcb1yc71iY8JYWsVeYMNoaMhvccl3d4+GNqyWPbadNZyKQYCIfp+Wabus
+ZdmnL961U9mwXNiqV9m1Ztu8e+e4R+S4XOW4ZOfKTO7Sb4qHh5GNipqXl4Cb
+i4OzlYe5mo+skYOvoo++oZ2joJG/o5mstKCenaeklbKsn6elpbCvr7u5uaSy
+rYLFnorIpI3Gt5HFppLOrJzBqpnLrpXFqZ/NspTQrpfSsJ7UtaLFr6fKtqvV
+vKvZv6fUurLSv5jRwanG1q/bwrXTwbXcxrzcybrYyK3Lw73hzcmHh82PkM6T
+k8+bnNWKjNSEhtaUldOam9mYmcqfoNefoNm7hNytrtemp9Wzs8uwquS8vdy/
+wNjDhdnFmMDAtNnIqenIjO/PlPPSiPfZl/bPg+vaqvXcpefcsvDjrcjGx8/O
+zsHYzMfe0Mnd0c3Q0d7d3dXT09nVycLhz8Tk0svk1c/p2sjg2dPq3dnh3tbk
+3Nzl4dzr4t/m6urExenNzezY1/DMzfHY2Ofizevl2Pbqxvju2Pvx0vnz3eTk
+5OHq5uTv6evl5evs6+/t5eTy6uXx6u328e/48/Lv7fPu5PHv8PPx7Pv35/T0
+8/r29fz79v7+/vT59+Xu8yH5BAAAAAAALAAAAAAfAB8AAAj+APsJHMjJWjxO
+oQYqFGjKUjxsnBZKxEaDUxEarCQOtEbjRica1jT2o2etE45OU0yJHMhqSqcb
+lqzNk4jqhjUvNXCoXNkPFY4aXqzdSLhwUg1tk6aw4sezHz9rU7xow+FFIT1L
+pqbcaIGqqcB86VjVsCElFKeZ/by1SJWKSFev/dL1KceqCKpULbQJjNfCSxAi
+9AT+KyUx3zJk6vLN9SclyKQW3vppEyWqyoxUA0uZ+KeQn59fyvws62OunzWy
+okBxS8XCmqgh89Y96ubEhKJ3zNY5YvSGWj8/c9wsU6dvyKdrLEK1k1GFRRV9
+gQSQWODhQ7QRfzBouBDskZsvF+D+lDCnZQUVGd6snaokRNU7QAsaNMBwIAQH
+DBs6UAg2oo2cNhUAck8qQlQSyjNCVOHNDplIwwEAAIygAQImKLBABgQYMEch
+P8RBASCQ7KPJDNpgAQQmKFCBQjXMBAAABmCAwcABGTzBAQENMHKFIyNQ4Mgi
+62STQhUqVBKPJ5hE4QkkGgyQgQYakPCECJEsoEAGhqxSzwgWwCPQJ1Bkgkk7
+hEDBjQ9WTDPNIiK0iQgvfzShwxYg6PCJPn8sMhAWO3CDRRbWqOBDDFjoMxBT
+An2jRCSUcHGKEt8o5E8WMQjhgCr9pJIIKDt8ohEpS7xDChf6dEGJQqN0egim
+/VwyCDT+KmQhUTZKGNJNF1tsQwkTrPZDiAPWDJIJU6o4EEMPPVyyUDvbdPMO
+N9y884006wjkCbI5JDDKQNxc4s0VDrADl0DswGCFN5dco5A3RhxxBQxHYJpO
+PnGdg2g65wjkTA/mItFDN515AkMP0PBbjh6/nKMHH8gYo0wxeKRTTw48XHPE
+C5cgqtA7n0QySA7yFJOHyMnsoQcex9ChBzA5DBLJJ+2IpI8VBTyw7TF5EJOH
+MXbwAYwxePiBiyoPFGAFZyLx0003/Nhjxx3I4HGHMEAPg4vV+3zTzT4ijUOO
+QvuYo4s48IjTT9j31KN2U/ukoQY5sczSiyy51PIKOL3cEgtsOLHkEks4dfM9
+Czi7KASOGGLMMkYaa5yhxhqtoFGGGGG0QsYuYdzChhhsmDFLGLYolMsutLTy
+iiuv0OKKK8KssUstZdxyiziQq0FGK7yQE0a1A3HNjz7A77MP8GcL7849xutz
+zzuGhhO6QAEBADs="};
+
+LOCAL UNITTEST_RESULT test_base64decoder_1()
+{
+       return test_base64decoder_common(test_base64decoder_testdata01_encoded, strlen(test_base64decoder_testdata01_encoded), test_base64decoder_testdata01_raw, sizeof(test_base64decoder_testdata01_raw));
+}
+
+LOCAL UNITTEST_RESULT test_base64decoder_2()
+{
+       return test_base64decoder_common(test_base64decoder_testdata02_encoded, strlen(test_base64decoder_testdata02_encoded), test_base64decoder_testdata02_raw, sizeof(test_base64decoder_testdata02_raw));
+}
+
+LOCAL UNITTEST_RESULT test_base64decoder_3()
+{
+       return test_base64decoder_common(test_base64decoder_testdata03_encoded, strlen(test_base64decoder_testdata03_encoded), test_base64decoder_testdata03_raw, sizeof(test_base64decoder_testdata03_raw));
+}
+
+LOCAL UNITTEST_RESULT test_base64decoder_4()
+{
+       return test_base64decoder_common(test_base64decoder_testdata04_encoded, strlen(test_base64decoder_testdata04_encoded), test_base64decoder_testdata04_raw, sizeof(test_base64decoder_testdata04_raw));
+}
+
+EXPORT VOID test_base64decoder_main(unittest_driver_t *driver)
+{
+       UNITTEST_DRIVER_REGIST(driver, test_base64decoder_1);
+       UNITTEST_DRIVER_REGIST(driver, test_base64decoder_2);
+       UNITTEST_DRIVER_REGIST(driver, test_base64decoder_3);
+       UNITTEST_DRIVER_REGIST(driver, test_base64decoder_4);
+}