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 //%/////////////////////////////////////////////////////////////////////////////
33
34
|
35 david.dillard 1.10 /** This class encodes binary data to base64 Strings and
|
36 karl 1.1 decodes Strings coded in base64 into the corresponding binary
37 data.
|
38 david.dillard 1.10 The base64 data representation is based on a 64-character alphabet:
|
39 karl 1.1 <pre>
|
40 david.dillard 1.10 Table 1: The Base64 Alphabet
|
41 karl 1.1
42 Value Encoding Value Encoding Value Encoding Value Encoding
43 0 A 17 R 34 i 51 z
44 1 B 18 S 35 j 52 0
45 2 C 19 T 36 k 53 1
46 3 D 20 U 37 l 54 2
47 4 E 21 V 38 m 55 3
48 5 F 22 W 39 n 56 4
49 6 G 23 X 40 o 57 5
50 7 H 24 Y 41 p 58 6
51 8 I 25 Z 42 q 59 7
52 9 J 26 a 43 r 60 8
53 10 K 27 b 44 s 61 9
54 11 L 28 c 45 t 62 +
55 12 M 29 d 46 u 63 /
56 13 N 30 e 47 v
57 14 O 31 f 48 w (pad) =
58 15 P 32 g 49 x
59 16 Q 33 h 50 y
60 </pre>
61 The input file is encoded 6 bits at a time into a single character
62 karl 1.1 in the 64-character alphabet. Where padding is required at the end
|
63 david.dillard 1.10 of the stream, the padding character is '='.
|
64 karl 1.1 Finally, the output stream should also be broken into lines to improve
|
65 david.dillard 1.10 human readability. This class breaks it at 76 characters and insert a
66 CR/LF into the stream. This increases the length by less than 3%.
|
67 karl 1.1 Since the decoding ingores characters that are outside the 64 character
|
68 david.dillard 1.10 alphabet, the CR, LF and padding character are dropped.
|
69 karl 1.1 */
70
71 #ifndef Pegasus_Base64_h
72 #define Pegasus_Base64_h
73
74 #include <Pegasus/Common/Config.h>
75 #include <Pegasus/Common/Array.h>
|
76 kumpf 1.4 #include <Pegasus/Common/Linkage.h>
|
77 mike 1.12 #include <Pegasus/Common/Buffer.h>
|
78 karl 1.1
79 PEGASUS_NAMESPACE_BEGIN
80
81
82 class PEGASUS_COMMON_LINKAGE Base64
83 {
84 public:
|
85 david.dillard 1.10 /**
|
86 mike 1.12 Encodes an Buffer into a base64 array.
|
87 david.dillard 1.10
|
88 mike 1.12 @param vby Buffer with the data to be encoded.
89 @return Buffer with the encoded data
|
90 david.dillard 1.10 @exception bad_alloc Thrown if there is insufficient memory.
|
91 karl 1.1 */
|
92 kumpf 1.14 static Buffer encode(const Buffer& vby);
|
93 david.dillard 1.10
|
94 karl 1.1 /**
|
95 mike 1.12 Decodes an base64 array into an Buffer
|
96 david.dillard 1.10
|
97 mike 1.12 @param str Buffer with the data to be decoded.
98 @return Buffer with the decoded data
|
99 david.dillard 1.10 @exception bad_alloc Thrown if there is insufficient memory.
|
100 karl 1.1 */
|
101 mike 1.12 static Buffer decode(const Buffer& str);
|
102 karl 1.1
103 private:
104 static char _Encode(Uint8 uc);
105 static Uint8 _Decode(char c);
|
106 david.dillard 1.10 static Boolean _IsBase64(char c);
|
107 karl 1.1 };
108
109
110 PEGASUS_NAMESPACE_END
111
112 #endif /* Pegasus_Base64_h */
|