34static size_t mb_base64_to_wchar(
unsigned char **in,
size_t *in_len, uint32_t *
buf,
size_t bufsize,
unsigned int *
state);
73#define CK(statement) do { if ((statement) < 0) return (-1); } while (0)
78static const unsigned char mbfl_base64_table[] = {
80 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,
82 0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,
84 0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,
86 0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,
88 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x2b,0x2f,0x00
98 filter->
cache = (c & 0xff) << 16;
101 filter->
cache |= (c & 0xff) << 8;
104 n = (filter->
status & 0xff00) >> 8;
108 filter->
status &= ~0xff00;
111 n = filter->
cache | (c & 0xff);
126 cache = filter->
cache;
128 filter->
status &= ~0xffff;
161 if (c == 0x0d || c == 0x0a || c == 0x20 || c == 0x09 || c == 0x3d) {
166 if (c >= 0x41 && c <= 0x5a) {
168 }
else if (c >= 0x61 && c <= 0x7a) {
170 }
else if (c >= 0x30 && c <= 0x39) {
172 }
else if (c == 0x2b) {
174 }
else if (c == 0x2f) {
212 cache = filter->
cache;
230static int decode_base64(
char c)
232 if (c >=
'A' && c <=
'Z') {
234 }
else if (c >=
'a' && c <=
'z') {
236 }
else if (c >=
'0' && c <=
'9') {
238 }
else if (c ==
'+') {
240 }
else if (c ==
'/') {
246static size_t mb_base64_to_wchar(
unsigned char **in,
size_t *in_len, uint32_t *
buf,
size_t bufsize,
unsigned int *
state)
250 unsigned char *
p = *in, *e =
p + *in_len;
251 uint32_t *
out =
buf, *limit =
buf + bufsize;
253 unsigned int bits = *
state & 0xFF, cache = *
state >> 8;
255 while (
p < e && (limit -
out) >= 3) {
256 unsigned char c = *
p++;
258 if (c ==
'\r' || c ==
'\n' || c ==
' ' || c ==
'\t' || c ==
'=') {
262 int value = decode_base64(c);
268 cache = (cache << 6) | (
value & 0x3F);
270 *
out++ = (cache >> 16) & 0xFF;
271 *
out++ = (cache >> 8) & 0xFF;
272 *
out++ = cache & 0xFF;
282 *
out++ = (cache >> 10) & 0xFF;
283 *
out++ = (cache >> 2) & 0xFF;
284 }
else if (bits == 12) {
285 *
out++ = (cache >> 4) & 0xFF;
289 *
state = (cache << 8) | (bits & 0xFF);
299 unsigned int bits = (
buf->state & 0x3) * 8;
300 unsigned int chars_output = ((
buf->state >> 2) & 0x3F) * 4;
301 unsigned int cache =
buf->state >> 8;
303 unsigned char *
out, *limit;
320 cache = (cache << 8) | (w & 0xFF);
323 if (chars_output > 72) {
324 out = mb_convert_buf_add2(
out,
'\r',
'\n');
327 out = mb_convert_buf_add4(
out,
328 mbfl_base64_table[(cache >> 18) & 0x3F],
329 mbfl_base64_table[(cache >> 12) & 0x3F],
330 mbfl_base64_table[(cache >> 6) & 0x3F],
331 mbfl_base64_table[cache & 0x3F]);
338 if (chars_output > 72) {
339 out = mb_convert_buf_add2(
out,
'\r',
'\n');
343 out = mb_convert_buf_add4(
out, mbfl_base64_table[(cache >> 2) & 0x3F], mbfl_base64_table[(cache & 0x3) << 4],
'=',
'=');
345 out = mb_convert_buf_add4(
out, mbfl_base64_table[(cache >> 10) & 0x3F], mbfl_base64_table[(cache >> 4) & 0x3F], mbfl_base64_table[(cache & 0xF) << 2],
'=');
348 buf->state = (cache << 8) | (((chars_output / 4) & 0x3F) << 2) | ((bits / 8) & 0x3);
zend_ffi_ctype_name_buf buf
const struct mbfl_convert_vtbl vtbl_8bit_b64
const mbfl_encoding mbfl_encoding_base64
int mbfl_filt_conv_base64dec_flush(mbfl_convert_filter *filter)
int mbfl_filt_conv_base64enc(int c, mbfl_convert_filter *filter)
int mbfl_filt_conv_base64enc_flush(mbfl_convert_filter *filter)
int mbfl_filt_conv_base64dec(int c, mbfl_convert_filter *filter)
const struct mbfl_convert_vtbl vtbl_b64_8bit
#define MBFL_ENCTYPE_GL_UNSAFE
void mbfl_filt_conv_common_ctor(mbfl_convert_filter *filter)
struct _mbfl_convert_filter mbfl_convert_filter
@ mbfl_no_encoding_base64
#define MB_CONVERT_BUF_STORE(buf, _out, _limit)
#define MB_CONVERT_BUF_ENSURE(buf, out, limit, needed)
#define MB_CONVERT_BUF_LOAD(buf, _out, _limit)
unsigned const char * end
output_function_t output_function
flush_function_t flush_function