00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef BASE64_HPP
00023 #define BASE64_HPP
00024
00025 #include <xercesc/util/XercesDefs.hpp>
00026 #include <xercesc/util/XMLUniDefs.hpp>
00027 #include <xercesc/framework/MemoryManager.hpp>
00028
00029 XERCES_CPP_NAMESPACE_BEGIN
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class Base64
00041 {
00042 public :
00043
00044 enum Conformance
00045 {
00046 Conf_RFC2045
00047 , Conf_Schema
00048 };
00049
00051
00070 static XMLByte* encode(const XMLByte* const inputData
00071 , const unsigned int inputLength
00072 , unsigned int* outputLength
00073 , MemoryManager* const memMgr = 0);
00074
00097 static XMLByte* decode(
00098 const XMLByte* const inputData
00099 , unsigned int* decodedLength
00100 , MemoryManager* const memMgr = 0
00101 , Conformance conform = Conf_RFC2045
00102 );
00103
00128 static XMLCh* decode(
00129 const XMLCh* const inputData
00130 , unsigned int* decodedLength
00131 , MemoryManager* const memMgr = 0
00132 , Conformance conform = Conf_RFC2045
00133 );
00134
00157 static XMLByte* decodeToXMLByte(
00158 const XMLCh* const inputData
00159 , unsigned int* decodedLength
00160 , MemoryManager* const memMgr = 0
00161 , Conformance conform = Conf_RFC2045
00162 );
00175 static int getDataLength(
00176 const XMLCh* const inputData
00177 , MemoryManager* const memMgr = 0
00178 , Conformance conform = Conf_RFC2045
00179 );
00180
00182
00198 static XMLCh* getCanonicalRepresentation
00199 (
00200 const XMLCh* const inputData
00201 , MemoryManager* const memMgr = 0
00202 , Conformance conform = Conf_RFC2045
00203 );
00204
00205 private :
00206
00207
00208
00209
00210
00211 static XMLByte* decode(
00212 const XMLByte* const inputData
00213 , unsigned int* outputLength
00214 , XMLByte*& canRepData
00215 , MemoryManager* const memMgr = 0
00216 , Conformance conform = Conf_RFC2045
00217 );
00218
00219 static void init();
00220
00221 static bool isData(const XMLByte& octet);
00222 static bool isPad(const XMLByte& octet);
00223
00224 static XMLByte set1stOctet(const XMLByte&, const XMLByte&);
00225 static XMLByte set2ndOctet(const XMLByte&, const XMLByte&);
00226 static XMLByte set3rdOctet(const XMLByte&, const XMLByte&);
00227
00228 static void split1stOctet(const XMLByte&, XMLByte&, XMLByte&);
00229 static void split2ndOctet(const XMLByte&, XMLByte&, XMLByte&);
00230 static void split3rdOctet(const XMLByte&, XMLByte&, XMLByte&);
00231
00232
00233
00234
00235 Base64();
00236 Base64(const Base64&);
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260 static const XMLByte base64Alphabet[];
00261 static const XMLByte base64Padding;
00262
00263 static XMLByte base64Inverse[];
00264 static bool isInitialized;
00265
00266 static const unsigned int quadsPerLine;
00267 };
00268
00269
00270
00271
00272 inline bool Base64::isPad(const XMLByte& octet)
00273 {
00274 return ( octet == base64Padding );
00275 }
00276
00277 inline XMLByte Base64::set1stOctet(const XMLByte& b1, const XMLByte& b2)
00278 {
00279 return (( b1 << 2 ) | ( b2 >> 4 ));
00280 }
00281
00282 inline XMLByte Base64::set2ndOctet(const XMLByte& b2, const XMLByte& b3)
00283 {
00284 return (( b2 << 4 ) | ( b3 >> 2 ));
00285 }
00286
00287 inline XMLByte Base64::set3rdOctet(const XMLByte& b3, const XMLByte& b4)
00288 {
00289 return (( b3 << 6 ) | b4 );
00290 }
00291
00292 inline void Base64::split1stOctet(const XMLByte& ch, XMLByte& b1, XMLByte& b2) {
00293 b1 = ch >> 2;
00294 b2 = ( ch & 0x3 ) << 4;
00295 }
00296
00297 inline void Base64::split2ndOctet(const XMLByte& ch, XMLByte& b2, XMLByte& b3) {
00298 b2 |= ch >> 4;
00299 b3 = ( ch & 0xf ) << 2;
00300 }
00301
00302 inline void Base64::split3rdOctet(const XMLByte& ch, XMLByte& b3, XMLByte& b4) {
00303 b3 |= ch >> 6;
00304 b4 = ( ch & 0x3f );
00305 }
00306
00307 XERCES_CPP_NAMESPACE_END
00308
00309 #endif