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

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

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2