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