Xerces-C++ 3.2.4

Base64.hpp
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/*
19 * $Id$
20 */
21
22#if !defined(XERCESC_INCLUDE_GUARD_BASE64_HPP)
23#define XERCESC_INCLUDE_GUARD_BASE64_HPP
24
25#include <xercesc/util/XercesDefs.hpp>
26#include <xercesc/util/XMLUniDefs.hpp>
27#include <xercesc/framework/MemoryManager.hpp>
28
29 XERCES_CPP_NAMESPACE_BEGIN
30
31//
32// This class provides encode/decode for RFC 2045 Base64 as
33// defined by RFC 2045, N. Freed and N. Borenstein.
34// RFC 2045: Multipurpose Internet Mail Extensions (MIME)
35// Part One: Format of Internet Message Bodies. Reference
36// 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
37// This class is used by XML Schema binary format validation
38//
39//
40 class XMLUTIL_EXPORT Base64
41{
42public :
43
44 enum Conformance
45 {
46 Conf_RFC2045
47 , Conf_Schema
48 };
49
51
67 static XMLByte* encode(const XMLByte* const inputData
68 , const XMLSize_t inputLength
69 , XMLSize_t* outputLength
70 , MemoryManager* const memMgr = 0);
71
91 static XMLByte* decode(
92 const XMLByte* const inputData
93 , XMLSize_t* decodedLength
94 , MemoryManager* const memMgr = 0
95 , Conformance conform = Conf_RFC2045
96 );
97
117 static XMLByte* decodeToXMLByte(
118 const XMLCh* const inputData
119 , XMLSize_t* decodedLength
120 , MemoryManager* const memMgr = 0
121 , Conformance conform = Conf_RFC2045
122 );
135 static int getDataLength(
136 const XMLCh* const inputData
137 , MemoryManager* const memMgr = 0
138 , Conformance conform = Conf_RFC2045
139 );
140
142
158 static XMLCh* getCanonicalRepresentation
159 (
160 const XMLCh* const inputData
161 , MemoryManager* const memMgr = 0
162 , Conformance conform = Conf_RFC2045
163 );
164
165private :
166
167 // -----------------------------------------------------------------------
168 // Helper methods
169 // -----------------------------------------------------------------------
170
171 static XMLByte* decode(
172 const XMLByte* const inputData
173 , XMLSize_t* outputLength
174 , XMLByte*& canRepData
175 , MemoryManager* const memMgr = 0
176 , Conformance conform = Conf_RFC2045
177 );
178
179 static bool isData(const XMLByte& octet);
180 static bool isPad(const XMLByte& octet);
181
182 static XMLByte set1stOctet(const XMLByte&, const XMLByte&);
183 static XMLByte set2ndOctet(const XMLByte&, const XMLByte&);
184 static XMLByte set3rdOctet(const XMLByte&, const XMLByte&);
185
186 static void split1stOctet(const XMLByte&, XMLByte&, XMLByte&);
187 static void split2ndOctet(const XMLByte&, XMLByte&, XMLByte&);
188 static void split3rdOctet(const XMLByte&, XMLByte&, XMLByte&);
189
190 // -----------------------------------------------------------------------
191 // Unimplemented constructors and operators
192 // -----------------------------------------------------------------------
193 Base64();
194 Base64(const Base64&);
195
196 // -----------------------------------------------------------------------
197 // Private data members
198 //
199 // base64Alphabet
200 // The Base64 alphabet (see RFC 2045).
201 //
202 // base64Padding
203 // Padding character (see RFC 2045).
204 //
205 // base64Inverse
206 // Table used in decoding base64.
207 //
208 // isInitialized
209 // Set once base64Inverse is initialized.
210 //
211 // quadsPerLine
212 // Number of quadruplets per one line. The encoded output
213 // stream must be represented in lines of no more
214 // than 19 quadruplets each.
215 //
216 // -----------------------------------------------------------------------
217
218 static const XMLByte base64Alphabet[];
219 static const XMLByte base64Padding;
220
221 static const XMLByte base64Inverse[];
222
223 static const unsigned int quadsPerLine;
224};
225
226// -----------------------------------------------------------------------
227// Helper methods
228// -----------------------------------------------------------------------
229 inline bool Base64::isPad(const XMLByte& octet)
230{
231 return ( octet == base64Padding );
232}
233
234 inline XMLByte Base64::set1stOctet(const XMLByte& b1, const XMLByte& b2)
235{
236 return (( b1 << 2 ) | ( b2 >> 4 ));
237}
238
239 inline XMLByte Base64::set2ndOctet(const XMLByte& b2, const XMLByte& b3)
240{
241 return (( b2 << 4 ) | ( b3 >> 2 ));
242}
243
244 inline XMLByte Base64::set3rdOctet(const XMLByte& b3, const XMLByte& b4)
245{
246 return (( b3 << 6 ) | b4 );
247}
248
249 inline void Base64::split1stOctet(const XMLByte& ch, XMLByte& b1, XMLByte& b2) {
250 b1 = ch >> 2;
251 b2 = ( ch & 0x3 ) << 4;
252}
253
254 inline void Base64::split2ndOctet(const XMLByte& ch, XMLByte& b2, XMLByte& b3) {
255 b2 |= ch >> 4; // combine with previous value
256 b3 = ( ch & 0xf ) << 2;
257}
258
259 inline void Base64::split3rdOctet(const XMLByte& ch, XMLByte& b3, XMLByte& b4) {
260 b3 |= ch >> 6; // combine with previous value
261 b4 = ( ch & 0x3f );
262}
263
264 XERCES_CPP_NAMESPACE_END
265
266#endif
MemoryManager.hpp
XMLUniDefs.hpp
XercesDefs.hpp
XERCES_CPP_NAMESPACE_BEGIN
#define XERCES_CPP_NAMESPACE_BEGIN
Definition: XercesDefs.hpp:112
XMLByte
unsigned char XMLByte
Definition: XercesDefs.hpp:65
XMLUTIL_EXPORT
#define XMLUTIL_EXPORT
Definition: XercesDefs.hpp:162
XERCES_CPP_NAMESPACE_END
#define XERCES_CPP_NAMESPACE_END
Definition: XercesDefs.hpp:113
XMLCh
uint16_t XMLCh
Definition: Xerces_autoconf_config.hpp:120
XMLSize_t
size_t XMLSize_t
Definition: Xerces_autoconf_config.hpp:112
Base64
Definition: Base64.hpp:41
Base64::encode
static XMLByte * encode(const XMLByte *const inputData, const XMLSize_t inputLength, XMLSize_t *outputLength, MemoryManager *const memMgr=0)
Encodes octets into Base64 data.
Base64::getCanonicalRepresentation
static XMLCh * getCanonicalRepresentation(const XMLCh *const inputData, MemoryManager *const memMgr=0, Conformance conform=Conf_RFC2045)
get canonical representation
Base64::decodeToXMLByte
static XMLByte * decodeToXMLByte(const XMLCh *const inputData, XMLSize_t *decodedLength, MemoryManager *const memMgr=0, Conformance conform=Conf_RFC2045)
Decodes Base64 data into octets.
Base64::decode
static XMLByte * decode(const XMLByte *const inputData, XMLSize_t *decodedLength, MemoryManager *const memMgr=0, Conformance conform=Conf_RFC2045)
Decodes Base64 data into octets.
Base64::getDataLength
static int getDataLength(const XMLCh *const inputData, MemoryManager *const memMgr=0, Conformance conform=Conf_RFC2045)
Get data length.
Base64::Conformance
Conformance
Definition: Base64.hpp:45
MemoryManager
Configurable memory manager.
Definition: MemoryManager.hpp:40