29
29
#include "CSEncode.h"
31
static const u_char base64Map[64] = {
31
static const u_char base64URLMap[64] = {
32
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
33
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
34
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
35
'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
36
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
37
'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
38
'w', 'x', 'y', 'z', '0', '1', '2', '3',
39
'4', '5', '6', '7', '8', '9', '-', '_'
41
static const u_char base64STDMap[64] = {
32
42
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
33
43
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
34
44
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
42
52
static const u_char decodeBase64Map[128] = {
43
0XBF, 0XFF, 0XF2, 0X2C, 0XBF, 0XFF, 0XF2, 0X24,
44
0X0, 0X0, 0X2E, 0X4C, 0X0, 0X0, 0X0, 0X3,
45
0X0, 0X0, 0X0, 0X3, 0XBF, 0XFF, 0XF1, 0X40,
46
0X0, 0X0, 0X0, 0X50, 0X8F, 0XE1, 0X56, 0XD8,
47
0X0, 0X30, 0X6, 0XEC, 0X0, 0X30, 0X6, 0XF0,
48
0X0, 0X0, 0X2E, 0X3E, 0X0, 0X0, 0X0, 0X3F,
53
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
54
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
55
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
56
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
57
0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
58
0XFF, 0XFF, 0XFF, 0X3E, 0XFF, 0X3E, 0XFF, 0X3F,
49
59
0X34, 0X35, 0X36, 0X37, 0X38, 0X39, 0X3A, 0X3B,
50
0X3C, 0X3D, 0X2C, 0X68, 0X90, 0X0, 0X17, 0XD8,
51
0XBF, 0X0, 0X1, 0X2, 0X3, 0X4, 0X5, 0X6,
52
0X7, 0X8, 0X9, 0XA, 0XB, 0XC, 0XD, 0XE,
53
0XF, 0X10, 0X11, 0X12, 0X13, 0X14, 0X15, 0X16,
54
0X17, 0X18, 0X19, 0X80, 0X0, 0X0, 0X0, 0X0,
55
0X0, 0X1A, 0X1B, 0X1C, 0X1D, 0X1E, 0X1F, 0X20,
60
0X3C, 0X3D, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
61
0XFF, 0X00, 0X01, 0X02, 0X03, 0X04, 0X05, 0X06,
62
0X07, 0X08, 0X09, 0X0A, 0X0B, 0X0C, 0X0D, 0X0E,
63
0X0F, 0X10, 0X11, 0X12, 0X13, 0X14, 0X15, 0X16,
64
0X17, 0X18, 0X19, 0XFF, 0XFF, 0XFF, 0XFF, 0X3F,
65
0XFF, 0X1A, 0X1B, 0X1C, 0X1D, 0X1E, 0X1F, 0X20,
56
66
0X21, 0X22, 0X23, 0X24, 0X25, 0X26, 0X27, 0X28,
57
67
0X29, 0X2A, 0X2B, 0X2C, 0X2D, 0X2E, 0X2F, 0X30,
58
0X31, 0X32, 0X33, 0X0, 0X90, 0X1B, 0XBA, 0X48,
68
0X31, 0X32, 0X33, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF,
62
static bool base64Encoded(const u_char *data, size_t len)
72
static bool base64Encoded(const u_char *data, size_t len, const u_char *vc)
158
184
return_(decoding);
188
char *base64Encode(const void *data, size_t len, char *encode_buffer, size_t encode_buffer_len)
190
return genericBase64Encode(data, len, encode_buffer, encode_buffer_len, base64STDMap);
194
void *base64Decode(const char *data, size_t len, void *decode_buffer, size_t decode_buffer_len)
196
return genericBase64Decode(data, len, decode_buffer, decode_buffer_len, base64STDMap);
200
char *base64UrlEncode(const void *data, size_t len, char *encode_buffer, size_t encode_buffer_len)
202
return genericBase64Encode(data, len, encode_buffer, encode_buffer_len, base64URLMap);
206
void *base64UrlDecode(const char *data, size_t len, void *decode_buffer, size_t decode_buffer_len)
208
return genericBase64Decode(data, len, decode_buffer, decode_buffer_len, base64URLMap);
162
212
//-----------------------------------------------------
163
213
void hmac_md5(u_char *text, size_t text_len, u_char *key, size_t key_len, Md5Digest *digest)