#include <base64.h>
Public Types | |
typedef unsigned char | byte_t |
typedef _E | char_type |
typedef _Tr | traits_type |
Public Member Functions | |
template<class _II, class _OI, class _State, class _Endline> | |
_II | put (_II _First, _II _Last, _OI _To, _State &_St, _Endline _Endl) const |
template<class _II, class _OI, class _State> | |
_II | get (_II _First, _II _Last, _OI _To, _State &_St) const |
Protected Member Functions | |
int | _getCharType (int _Ch) const |
Classes | |
struct | crlf |
struct | crlfsp |
struct | noline |
struct | three2four |
Definition at line 42 of file base64.h.
typedef _Tr base64< _E, _Tr >::traits_type |
int base64< _E, _Tr >::_getCharType | ( | int | _Ch | ) | const [inline, protected] |
Definition at line 352 of file base64.h.
References _base64Chars, _EQUAL_CHAR, and _UNKNOWN_CHAR.
Referenced by base64< _E, _Tr >::get().
00353 { 00354 if(_base64Chars[62] == _Ch) 00355 return 62; 00356 00357 if(_base64Chars[63] == _Ch) 00358 return 63; 00359 00360 if((_base64Chars[0] <= _Ch) && (_base64Chars[25] >= _Ch)) 00361 return _Ch - _base64Chars[0]; 00362 00363 if((_base64Chars[26] <= _Ch) && (_base64Chars[51] >= _Ch)) 00364 return _Ch - _base64Chars[26] + 26; 00365 00366 if((_base64Chars[52] <= _Ch) && (_base64Chars[61] >= _Ch)) 00367 return _Ch - _base64Chars[52] + 52; 00368 00369 if(_Ch == _Tr::to_int_type('=')) 00370 return _EQUAL_CHAR; 00371 00372 return _UNKNOWN_CHAR; 00373 }
_II base64< _E, _Tr >::get | ( | _II | _First, | |
_II | _Last, | |||
_OI | _To, | |||
_State & | _St | |||
) | const [inline] |
Definition at line 215 of file base64.h.
References _EQUAL_CHAR, base64< _E, _Tr >::_getCharType(), _IOS_EOFBIT, _IOS_FAILBIT, _UNKNOWN_CHAR, base64< _E, _Tr >::three2four::b64_0(), base64< _E, _Tr >::three2four::b64_1(), base64< _E, _Tr >::three2four::b64_2(), base64< _E, _Tr >::three2four::b64_3(), base64< _E, _Tr >::three2four::get_0(), base64< _E, _Tr >::three2four::get_1(), base64< _E, _Tr >::three2four::get_2(), and base64< _E, _Tr >::three2four::zero().
Referenced by XmlRpc::XmlRpcValue::binaryFromXml().
00216 { 00217 three2four _3to4; 00218 int _Char; 00219 00220 while(_First != _Last) 00221 { 00222 00223 // Take octet 00224 _3to4.zero(); 00225 00226 // -- 0 -- 00227 // Search next valid char... 00228 while((_Char = _getCharType(*_First)) < 0 && _Char == _UNKNOWN_CHAR) 00229 { 00230 if(++_First == _Last) 00231 { 00232 _St |= _IOS_FAILBIT|_IOS_EOFBIT; return _First; // unexpected EOF 00233 } 00234 } 00235 00236 if(_Char == _EQUAL_CHAR){ 00237 // Error! First character in octet can't be '=' 00238 _St |= _IOS_FAILBIT; 00239 return _First; 00240 } 00241 else 00242 _3to4.b64_0(_Char); 00243 00244 00245 // -- 1 -- 00246 // Search next valid char... 00247 while(++_First != _Last) 00248 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR) 00249 break; 00250 00251 if(_First == _Last) { 00252 _St |= _IOS_FAILBIT|_IOS_EOFBIT; // unexpected EOF 00253 return _First; 00254 } 00255 00256 if(_Char == _EQUAL_CHAR){ 00257 // Error! Second character in octet can't be '=' 00258 _St |= _IOS_FAILBIT; 00259 return _First; 00260 } 00261 else 00262 _3to4.b64_1(_Char); 00263 00264 00265 // -- 2 -- 00266 // Search next valid char... 00267 while(++_First != _Last) 00268 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR) 00269 break; 00270 00271 if(_First == _Last) { 00272 // Error! Unexpected EOF. Must be '=' or base64 character 00273 _St |= _IOS_FAILBIT|_IOS_EOFBIT; 00274 return _First; 00275 } 00276 00277 if(_Char == _EQUAL_CHAR){ 00278 // OK! 00279 _3to4.b64_2(0); 00280 _3to4.b64_3(0); 00281 00282 // chek for EOF 00283 if(++_First == _Last) 00284 { 00285 // Error! Unexpected EOF. Must be '='. Ignore it. 00286 //_St |= _IOS_BADBIT|_IOS_EOFBIT; 00287 _St |= _IOS_EOFBIT; 00288 } 00289 else 00290 if(_getCharType(*_First) != _EQUAL_CHAR) 00291 { 00292 // Error! Must be '='. Ignore it. 00293 //_St |= _IOS_BADBIT; 00294 } 00295 else 00296 ++_First; // Skip '=' 00297 00298 // write 1 byte to output 00299 *_To = (byte_t) _3to4.get_0(); 00300 return _First; 00301 } 00302 else 00303 _3to4.b64_2(_Char); 00304 00305 00306 // -- 3 -- 00307 // Search next valid char... 00308 while(++_First != _Last) 00309 if((_Char = _getCharType(*_First)) != _UNKNOWN_CHAR) 00310 break; 00311 00312 if(_First == _Last) { 00313 // Unexpected EOF. It's error. But ignore it. 00314 //_St |= _IOS_FAILBIT|_IOS_EOFBIT; 00315 _St |= _IOS_EOFBIT; 00316 00317 return _First; 00318 } 00319 00320 if(_Char == _EQUAL_CHAR) 00321 { 00322 // OK! 00323 _3to4.b64_3(0); 00324 00325 // write to output 2 bytes 00326 *_To = (byte_t) _3to4.get_0(); 00327 *_To = (byte_t) _3to4.get_1(); 00328 00329 ++_First; // set position to next character 00330 00331 return _First; 00332 } 00333 else 00334 _3to4.b64_3(_Char); 00335 00336 00337 // write to output 3 bytes 00338 *_To = (byte_t) _3to4.get_0(); 00339 *_To = (byte_t) _3to4.get_1(); 00340 *_To = (byte_t) _3to4.get_2(); 00341 00342 ++_First; 00343 00344 00345 } // while(_First != _Last) 00346 00347 return (_First); 00348 }
_II base64< _E, _Tr >::put | ( | _II | _First, | |
_II | _Last, | |||
_OI | _To, | |||
_State & | _St, | |||
_Endline | _Endl | |||
) | const [inline] |
Definition at line 155 of file base64.h.
References _base64Chars, base64< _E, _Tr >::three2four::b64_0(), base64< _E, _Tr >::three2four::b64_1(), base64< _E, _Tr >::three2four::b64_2(), base64< _E, _Tr >::three2four::b64_3(), base64< _E, _Tr >::three2four::set_0(), base64< _E, _Tr >::three2four::set_1(), base64< _E, _Tr >::three2four::set_2(), and base64< _E, _Tr >::three2four::zero().
Referenced by XmlRpc::XmlRpcValue::binaryToXml(), and XmlRpc::XmlRpcValue::write().
00156 { 00157 three2four _3to4; 00158 int line_octets = 0; 00159 00160 while(_First != _Last) 00161 { 00162 _3to4.zero(); 00163 00164 // берём по 3 символа 00165 _3to4.set_0(*_First); 00166 _First++; 00167 00168 if(_First == _Last) 00169 { 00170 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To; 00171 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To; 00172 *_To = _Tr::to_char_type('='); ++_To; 00173 *_To = _Tr::to_char_type('='); ++_To; 00174 goto __end; 00175 } 00176 00177 _3to4.set_1(*_First); 00178 _First++; 00179 00180 if(_First == _Last) 00181 { 00182 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To; 00183 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To; 00184 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To; 00185 *_To = _Tr::to_char_type('='); ++_To; 00186 goto __end; 00187 } 00188 00189 _3to4.set_2(*_First); 00190 _First++; 00191 00192 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_0()]); ++_To; 00193 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_1()]); ++_To; 00194 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_2()]); ++_To; 00195 *_To = _Tr::to_char_type(_base64Chars[_3to4.b64_3()]); ++_To; 00196 00197 if(line_octets == 17) // base64 позволяет длину строки не более 72 символов 00198 { 00199 //_To = _Endl(_To); 00200 *_To = '\n'; ++_To; 00201 line_octets = 0; 00202 } 00203 else 00204 ++line_octets; 00205 } 00206 00207 __end: ; 00208 00209 return (_First); 00210 00211 }