rel_1.6.0 init

This commit is contained in:
guocheng.kgc 2020-06-18 20:06:52 +08:00 committed by shengdong.dsd
commit 27b3e2883d
19359 changed files with 8093121 additions and 0 deletions

View file

@ -0,0 +1,119 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#include "base64.h"
#include <stdio.h>
static const unsigned char encoding_table[] = {
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
static const unsigned char decoding_table[] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 0, 0, 0,
0, 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, 0, 0, 0, 0, 0,
0, 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, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
static const unsigned char mod_table[] = { 0, 2, 1 };
unsigned char *base64_encode(const unsigned char *input, int input_len,
unsigned char *output, int *output_len)
{
int i, j;
int o_len = 4 * ((input_len + 2) / 3);
if (!input || !output || !output_len) {
return NULL;
}
if (output_len) {
*output_len = o_len;
}
for (i = 0, j = 0; i < input_len;) {
unsigned int octet_a = i < input_len ? input[i++] : 0;
unsigned int octet_b = i < input_len ? input[i++] : 0;
unsigned int octet_c = i < input_len ? input[i++] : 0;
unsigned int triple = (octet_a << 0x10) + (octet_b << 0x08) + octet_c;
output[j++] = encoding_table[(triple >> 18) & 0x3F];
output[j++] = encoding_table[(triple >> 12) & 0x3F];
output[j++] = encoding_table[(triple >> 6) & 0x3F];
output[j++] = encoding_table[(triple >> 0) & 0x3F];
}
for (i = 0; i < mod_table[input_len % 3]; i++) {
output[o_len - 1 - i] = '=';
}
return output;
}
unsigned char *base64_decode(const unsigned char *input, int input_len,
unsigned char *output, int *output_len)
{
int i, j;
int o_len = input_len / 4 * 3;
if (!input || !output || !output_len) {
return NULL;
}
if (input[input_len - 1] == '=') {
o_len--;
}
if (input[input_len - 2] == '=') {
o_len--;
}
if (output_len) {
*output_len = o_len;
}
for (i = 0, j = 0; i < input_len;) {
unsigned int sextet_a = decoding_table[input[i++]];
unsigned int sextet_b = decoding_table[input[i++]];
unsigned int sextet_c = decoding_table[input[i++]];
unsigned int sextet_d = decoding_table[input[i++]];
unsigned int triple = (sextet_a << 18)
+ (sextet_b << 12)
+ (sextet_c << 6)
+ (sextet_d << 0);
if (j < o_len) {
output[j++] = (triple >> 16) & 0xFF;
}
if (j < o_len) {
output[j++] = (triple >> 8) & 0xFF;
}
if (j < o_len) {
output[j++] = (triple >> 0) & 0xFF;
}
}
return output;
}

View file

@ -0,0 +1,48 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/
#ifndef _BASE64_H_
#define _BASE64_H_
#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
extern "C" {
#endif
#include <stdlib.h>
#include <string.h>
/**
* @brief base64 encode
*
* @param[in] input: input byte stream
* @param[in] input_len: input stream length in byte
* @param[out] output: base64 encoded string
* @param[in/out] output_len: [in] for output buffer size, [out] for
* base64 encoded string length
* @Note output buffer is not NULL-terminated
*
* @retval output buffer on success, otherwise NULL will return
*/
unsigned char *base64_encode(const unsigned char *input, int input_len,
unsigned char *output, int *output_len);
/**
* @brief base64 decode
*
* @param[in] input: input byte stream
* @param[in] input_len: input stream length in byte
* @param[out] output: base64 decoded string
* @param[in/out] output_len: [in] for output buffer size, [out] for
* base64 decoded string length
* @Note output buffer is not NULL-terminated
* @retval output buffer on success, otherwise NULL will return
*/
unsigned char *base64_decode(const unsigned char *input, int input_len,
unsigned char *output, int *output_len);
#if defined(__cplusplus) /* If this is a C++ compiler, use C linkage */
}
#endif
#endif

View file

@ -0,0 +1,7 @@
NAME := base64
$(NAME)_TYPE := share
$(NAME)_SOURCES := base64.c
GLOBAL_INCLUDES += .

View file

@ -0,0 +1,5 @@
src = Split('''
base64.c
''')
component = aos_component('base64', src)