8 #ifndef BASE64_CENCODE_H 9 #define BASE64_CENCODE_H 13 step_A, step_B, step_C
18 base64_encodestep step;
25 inline char base64_encode_value(
char value_in);
27 inline int base64_encode_block(
const char* plaintext_in,
int length_in,
char* code_out,
base64_encodestate* state_in);
39 const int CHARS_PER_LINE = 72;
43 state_in->step = step_A;
45 state_in->stepcount = 0;
48 inline char base64_encode_value(
char value_in)
50 static const char* encoding =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
51 if (value_in > 63)
return '=';
52 return encoding[(int)value_in];
55 inline int base64_encode_block(
const char* plaintext_in,
int length_in,
char* code_out,
base64_encodestate* state_in)
57 const char* plainchar = plaintext_in;
58 const char*
const plaintextend = plaintext_in + length_in;
59 char* codechar = code_out;
63 result = state_in->result;
65 switch (state_in->step)
70 if (plainchar == plaintextend)
72 state_in->result = result;
73 state_in->step = step_A;
74 return codechar - code_out;
76 fragment = *plainchar++;
77 result = (fragment & 0x0fc) >> 2;
78 *codechar++ = base64_encode_value(result);
79 result = (fragment & 0x003) << 4;
81 if (plainchar == plaintextend)
83 state_in->result = result;
84 state_in->step = step_B;
85 return codechar - code_out;
87 fragment = *plainchar++;
88 result |= (fragment & 0x0f0) >> 4;
89 *codechar++ = base64_encode_value(result);
90 result = (fragment & 0x00f) << 2;
92 if (plainchar == plaintextend)
94 state_in->result = result;
95 state_in->step = step_C;
96 return codechar - code_out;
98 fragment = *plainchar++;
99 result |= (fragment & 0x0c0) >> 6;
100 *codechar++ = base64_encode_value(result);
101 result = (fragment & 0x03f) >> 0;
102 *codechar++ = base64_encode_value(result);
104 ++(state_in->stepcount);
105 #ifdef DENDRO_VTK_WRAP_COORDS 106 if (state_in->stepcount == CHARS_PER_LINE/4)
109 state_in->stepcount = 0;
115 return codechar - code_out;
120 char* codechar = code_out;
122 switch (state_in->step)
125 *codechar++ = base64_encode_value(state_in->result);
130 *codechar++ = base64_encode_value(state_in->result);
137 #ifdef DENDRO_VTK_WRAP_COORDS 141 return codechar - code_out;