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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2