40 #ifndef _binarytool_cpp
41 #define _binarytool_cpp
46 #include "binarybuffer.h"
47 #include "exception.h"
91 static const String Base64Chars =
92 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
93 "abcdefghijklmnopqrstuvwxyz"
104 String::const_iterator Progress = EncodedString.begin();
112 unsigned char Second;
114 unsigned char Fourth;
116 while(Progress<EncodedString.end())
123 First = Base64Chars.find(*(Progress+0));
124 Second = Base64Chars.find(*(Progress+1));
125 Third = *(Progress+2)==
'=' ? 0 : Base64Chars.find(*(Progress+2));
128 if(Output+1>Results.
Size)
132 *(Results.
Binary+Output+0) = (First << 2) + ((Second & 0x30) >> 4);
133 *(Results.
Binary+Output+1) = ((Second & 0xf) << 4) + ((Third & 0x3c) >> 2);
134 if(*(Progress+3)!=
'=')
137 if(Output+2>Results.
Size)
140 Fourth = Base64Chars.find(*(Progress+3));
141 *(Results.
Binary+Output+2) = ((Third & 0x3) << 6) + Fourth;
145 if(Progress>EncodedString.end())
176 this->
Size = DataString.size();
178 memcpy(this->
Binary, DataString.c_str(), this->
Size);
184 if (RH.
Binary == this->Binary)
242 Base64DecodeImpl(EncodedBinaryData,*
this);
257 Byte* TargetBuffer =
new Byte[NewSize];
259 memcpy(TargetBuffer, this->
Binary, this->
Size);
260 memcpy(TargetBuffer+this->
Size, OtherBuffer, ByteSize);
263 this->
Binary = TargetBuffer;
281 {
return (isalnum(Character) || (Character ==
'+') || (Character ==
'/') || (Character ==
'=')); }
297 unsigned char char_array_3[3];
298 unsigned char char_array_4[4];
302 char_array_3[i++] = *(BytesToEncode++);
305 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
306 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
307 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
308 char_array_4[3] = char_array_3[2] & 0x3f;
310 for(i = 0; (i <4) ; i++)
311 { Results += Base64Chars[char_array_4[i]]; }
318 for(j = i; j < 3; j++)
319 { char_array_3[j] =
'\0'; }
321 char_array_4[0] = (char_array_3[0] & 0xfc) >> 2;
322 char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4);
323 char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6);
324 char_array_4[3] = char_array_3[2] & 0x3f;
326 for (j = 0; (j < i + 1); j++)
327 { Results += Base64Chars[char_array_4[j]]; }
342 Base64DecodeImpl(EncodedString, Results);
349 if(EncodedString.size()<4)
352 return EncodedString.size()/4*3 - ( EncodedString.at(EncodedString.size()-2)==
'=' ?1:0) - ( EncodedString.at(EncodedString.size()-1)==
'=' ?1:0);
356 {
return (Length+2)/3*4; }