| API Docs for SAX and DOM |

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

# Base64.hpp

Go to the documentation of this file.

    00001 /*
    00002  * Copyright 2001,2004 The Apache Software Foundation.
    00003  *
    00004  * Licensed under the Apache License, Version 2.0 (the "License");
    00005  * you may not use this file except in compliance with the License.
    00006  * You may obtain a copy of the License at
    00007  *
    00008  *      http://www.apache.org/licenses/LICENSE-2.0
    00009  *
    00010  * Unless required by applicable law or agreed to in writing, software
    00011  * distributed under the License is distributed on an "AS IS" BASIS,
    00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    00013  * See the License for the specific language governing permissions and
    00014  * limitations under the License.
    00015  */
    00016
    00017 /*
    00018  * $Id: Base64.hpp 231219 2005-08-10 12:28:35Z amassari $
    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 // This class provides encode/decode for RFC 2045 Base64 as
    00032 // defined by RFC 2045, N. Freed and N. Borenstein.
    00033 // RFC 2045: Multipurpose Internet Mail Extensions (MIME)
    00034 // Part One: Format of Internet Message Bodies. Reference
    00035 // 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
    00036 // This class is used by XML Schema binary format validation
    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     //  Helper methods
    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     //  Unimplemented constructors and operators
    00233     // -----------------------------------------------------------------------
    00234     Base64();
    00235     Base64(const Base64&);
    00236
    00237     // -----------------------------------------------------------------------
    00238     //  Private data members
    00239     //
    00240     //  base64Alphabet
    00241     //     The Base64 alphabet (see RFC 2045).
    00242     //
    00243     //  base64Padding
    00244     //     Padding character (see RFC 2045).
    00245     //
    00246     //  base64Inverse
    00247     //     Table used in decoding base64.
    00248     //
    00249     //  isInitialized
    00250     //     Set once base64Inverse is initalized.
    00251     //
    00252     //  quadsPerLine
    00253     //     Number of quadruplets per one line. The encoded output
    00254     //     stream must be represented in lines of no more
    00255     //     than 19 quadruplets each.
    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 //  Helper methods
    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;  // combine with previous value
    00298     b3 = ( ch & 0xf ) << 2;
    00299 }
    00300
    00301 inline void Base64::split3rdOctet(const XMLByte& ch, XMLByte& b3, XMLByte& b4) {
    00302     b3 |= ch >> 6;  // combine with previous value
    00303     b4 = ( ch & 0x3f );
    00304 }
    00305
    00306 XERCES_CPP_NAMESPACE_END
    00307
    00308 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.