(file) Return to Base64.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

  1 martin 1.15 //%LICENSE////////////////////////////////////////////////////////////////
  2 martin 1.16 //
  3 martin 1.15 // Licensed to The Open Group (TOG) under one or more contributor license
  4             // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
  5             // this work for additional information regarding copyright ownership.
  6             // Each contributor licenses this file to you under the OpenPegasus Open
  7             // Source License; you may not use this file except in compliance with the
  8             // License.
  9 martin 1.16 //
 10 martin 1.15 // Permission is hereby granted, free of charge, to any person obtaining a
 11             // copy of this software and associated documentation files (the "Software"),
 12             // to deal in the Software without restriction, including without limitation
 13             // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 14             // and/or sell copies of the Software, and to permit persons to whom the
 15             // Software is furnished to do so, subject to the following conditions:
 16 martin 1.16 //
 17 martin 1.15 // The above copyright notice and this permission notice shall be included
 18             // in all copies or substantial portions of the Software.
 19 martin 1.16 //
 20 martin 1.15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 21 martin 1.16 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 22 martin 1.15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 23             // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 24             // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 25             // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 26             // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27 martin 1.16 //
 28 martin 1.15 //////////////////////////////////////////////////////////////////////////
 29 karl   1.1  //
 30             //%/////////////////////////////////////////////////////////////////////////////
 31             
 32             
 33 david.dillard 1.10 /** This class encodes binary data to base64 Strings and
 34 karl          1.1      decodes Strings coded in base64 into the corresponding binary
 35                        data.
 36 david.dillard 1.10     The base64 data representation is based on a 64-character alphabet:
 37 karl          1.1      <pre>
 38 david.dillard 1.10                        Table 1: The Base64 Alphabet
 39 karl          1.1  
 40                          Value Encoding  Value Encoding  Value Encoding  Value Encoding
 41                               0 A            17 R            34 i            51 z
 42                               1 B            18 S            35 j            52 0
 43                               2 C            19 T            36 k            53 1
 44                               3 D            20 U            37 l            54 2
 45                               4 E            21 V            38 m            55 3
 46                               5 F            22 W            39 n            56 4
 47                               6 G            23 X            40 o            57 5
 48                               7 H            24 Y            41 p            58 6
 49                               8 I            25 Z            42 q            59 7
 50                               9 J            26 a            43 r            60 8
 51                              10 K            27 b            44 s            61 9
 52                              11 L            28 c            45 t            62 +
 53                              12 M            29 d            46 u            63 /
 54                              13 N            30 e            47 v
 55                              14 O            31 f            48 w         (pad) =
 56                              15 P            32 g            49 x
 57                              16 Q            33 h            50 y
 58                        </pre>
 59                        The input file is encoded 6 bits at a time into a single character
 60 karl          1.1      in the 64-character alphabet. Where padding is required at the end
 61 david.dillard 1.10     of the stream, the padding character is '='.
 62 karl          1.1      Finally, the output stream should also be broken into lines to improve
 63 david.dillard 1.10     human readability.  This class breaks it at 76 characters and insert a
 64                        CR/LF into the stream.  This increases the length by less than 3%.
 65 karl          1.1      Since the decoding ingores characters that are outside the 64 character
 66 david.dillard 1.10     alphabet, the CR, LF and padding character are dropped.
 67 karl          1.1  */
 68                    
 69                    #ifndef Pegasus_Base64_h
 70                    #define Pegasus_Base64_h
 71                    
 72                    #include <Pegasus/Common/Config.h>
 73                    #include <Pegasus/Common/Array.h>
 74 kumpf         1.4  #include <Pegasus/Common/Linkage.h>
 75 mike          1.12 #include <Pegasus/Common/Buffer.h>
 76 karl          1.1  
 77                    PEGASUS_NAMESPACE_BEGIN
 78                    
 79                    
 80                    class PEGASUS_COMMON_LINKAGE Base64
 81                    {
 82                    public:
 83 david.dillard 1.10     /**
 84 mike          1.12         Encodes an Buffer into a base64 array.
 85 david.dillard 1.10 
 86 mike          1.12         @param vby Buffer with the data to be encoded.
 87                            @return Buffer with the encoded data
 88 david.dillard 1.10         @exception bad_alloc Thrown if there is insufficient memory.
 89 karl          1.1      */
 90 kumpf         1.14     static Buffer encode(const Buffer& vby);
 91 david.dillard 1.10 
 92 karl          1.1      /**
 93 mike          1.12         Decodes an base64 array into an Buffer
 94 david.dillard 1.10 
 95 mike          1.12         @param str Buffer with the data to be decoded.
 96                            @return Buffer with the decoded data
 97 david.dillard 1.10         @exception bad_alloc Thrown if there is insufficient memory.
 98 karl          1.1      */
 99 mike          1.12     static Buffer decode(const Buffer& str);
100 karl          1.1  
101                    private:
102                        static char _Encode(Uint8 uc);
103                        static Uint8 _Decode(char c);
104 david.dillard 1.10     static Boolean _IsBase64(char c);
105 karl          1.1  };
106                    
107                    
108                    PEGASUS_NAMESPACE_END
109                    
110                    #endif /* Pegasus_Base64_h */

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2