5 t_uint8 mask = 1 << (7-(p_offset&7));
7 byte = (byte & ~mask) | (state ? mask : 0);
10 for(
t_size walk = 0; walk < bits; ++walk) {
12 set_bit(stream, offset+walk, bit != 0);
19 t_size textLen = strlen(text);
20 if (textLen % 4 != 0)
throw pfc::exception_invalid_params();
21 t_size outLen = (textLen / 4) * 3;
24 if (text[textLen-1] ==
'=') {
26 if (text[textLen-1] ==
'=') {
37 static const char alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
39 for(
t_size walk = 0; walk < PFC_TABSIZE(alphabetRev); ++walk) alphabetRev[walk] = 0xFF;
40 for(
t_size walk = 0; walk < PFC_TABSIZE(alphabet); ++walk) alphabetRev[ (
unsigned) alphabet[walk]] = (
t_uint8)walk;
41 const t_size textLen = strlen(text);
43 if (textLen % 4 != 0)
throw pfc::exception_invalid_params();
44 if (textLen == 0)
return;
49 const t_size max = textLen - 4;
51 for(; textWalk < max; textWalk ++) {
53 if (v == 0xFF)
throw pfc::exception_invalid_params();
60 for(; textWalk < textLen; textWalk ++) {
61 const char c = text[textWalk];
64 if (v == 0xFF)
throw pfc::exception_invalid_params();
68 for(; textWalk < textLen; textWalk ++) {
69 if (text[textWalk] !=
'=')
throw pfc::exception_invalid_params();
71 memcpy(reinterpret_cast<t_uint8*>(out) + (outWritePtr/8), temp, tempWritePtr/8);
78 static const char alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
83 for(
t_size walk = 0; walk < inSize; ++walk) {
87 while ( shift >= 6 ) {
89 out << format_char( alphabet[(accum >> shift) & 0x3F] );
93 out <<
format_char( alphabet[(accum & 0xF)<<2] ) <<
"=";
94 }
else if (shift == 2) {
95 out <<
format_char( alphabet[(accum & 0x3)<<4] ) <<
"==";
void base64_decode(const char *text, void *out)
void base64_encode(pfc::string_base &out, const void *in, t_size inSize)
static void set_bit(t_uint8 *p_stream, size_t p_offset, bool state)
t_size base64_decode_estimate(const char *text)
void base64_encode_append(pfc::string_base &out, const void *in, t_size inSize)
static void set_bits(t_uint8 *stream, t_size offset, t_size word, t_size bits)