/usr/include/xercesc/util/Base64.hpp is in libxerces-c-dev 3.2.0+debian-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | /*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: Base64.hpp 932889 2010-04-11 13:10:10Z borisk $
*/
#if !defined(XERCESC_INCLUDE_GUARD_BASE64_HPP)
#define XERCESC_INCLUDE_GUARD_BASE64_HPP
#include <xercesc/util/XercesDefs.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/framework/MemoryManager.hpp>
XERCES_CPP_NAMESPACE_BEGIN
//
// This class provides encode/decode for RFC 2045 Base64 as
// defined by RFC 2045, N. Freed and N. Borenstein.
// RFC 2045: Multipurpose Internet Mail Extensions (MIME)
// Part One: Format of Internet Message Bodies. Reference
// 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
// This class is used by XML Schema binary format validation
//
//
class XMLUTIL_EXPORT Base64
{
public :
enum Conformance
{
Conf_RFC2045
, Conf_Schema
};
//@{
/**
* Encodes octets into Base64 data
*
* NOTE: The returned buffer is dynamically allocated and is the
* responsibility of the caller to delete it when not longer needed.
* Use the memory manager to release the returned buffer or
* operator delete() if none was provided.
*
* @param inputData Binary data in XMLByte stream.
* @param inputLength Length of the XMLByte stream.
* @param outputLength Length of the encoded Base64 byte stream.
* @param memMgr client provided memory manager
* @return Encoded Base64 data in XMLByte stream,
* or NULL if input data can not be encoded.
*/
static XMLByte* encode(const XMLByte* const inputData
, const XMLSize_t inputLength
, XMLSize_t* outputLength
, MemoryManager* const memMgr = 0);
/**
* Decodes Base64 data into octets
*
* NOTE: The returned buffer is dynamically allocated and is the
* responsibility of the caller to delete it when not longer needed.
* Use the memory manager to release the returned buffer or
* operator delete() if none was provided.
*
* @param inputData Base64 data in XMLByte stream.
* @param decodedLength Length of decoded XMLByte stream.
* @param memMgr client provided memory manager
* @param conform conformance specified: if the input data conforms to the
* RFC 2045 it is allowed to have any number of whitespace
* characters inside; if it conforms to the XMLSchema specs,
* it is allowed to have at most one whitespace character
* between the quartets
* @return Decoded binary data in XMLByte stream,
* or NULL if input data can not be decoded.
*/
static XMLByte* decode(
const XMLByte* const inputData
, XMLSize_t* decodedLength
, MemoryManager* const memMgr = 0
, Conformance conform = Conf_RFC2045
);
/**
* Decodes Base64 data into octets
*
* NOTE: The returned buffer is dynamically allocated and is the
* responsibility of the caller to delete it when not longer needed.
* Use the memory manager to release the returned buffer or
* operator delete() if none was provided.
*
* @param inputData Base64 data in XMLCh stream.
* @param decodedLength Length of decoded XMLByte stream.
* @param memMgr client provided memory manager
* @param conform conformance specified: if the input data conforms to the
* RFC 2045 it is allowed to have any number of whitespace
* characters inside; if it conforms to the XMLSchema specs,
* it is allowed to have at most one whitespace character
* between the quartets
* @return Decoded binary data in XMLByte stream,
* or NULL if input data can not be decoded.
*/
static XMLByte* decodeToXMLByte(
const XMLCh* const inputData
, XMLSize_t* decodedLength
, MemoryManager* const memMgr = 0
, Conformance conform = Conf_RFC2045
);
/**
* Get data length
*
* Returns length of decoded data given an array
* containing encoded data.
*
* @param inputData Base64 data in XMLCh stream.
* @param memMgr client provided memory manager
* @param conform conformance specified
* @return Length of decoded data,
* or -1 if input data can not be decoded.
*/
static int getDataLength(
const XMLCh* const inputData
, MemoryManager* const memMgr = 0
, Conformance conform = Conf_RFC2045
);
//@}
/**
* get canonical representation
*
* Caller is responsible for the proper deallocation
* of the string returned.
*
* @param inputData A string containing the Base64
* @param memMgr client provided memory manager
* @param conform conformance specified
*
* return: the canonical representation of the Base64
* if it is a valid Base64
* 0 otherwise
*/
static XMLCh* getCanonicalRepresentation
(
const XMLCh* const inputData
, MemoryManager* const memMgr = 0
, Conformance conform = Conf_RFC2045
);
private :
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
static XMLByte* decode(
const XMLByte* const inputData
, XMLSize_t* outputLength
, XMLByte*& canRepData
, MemoryManager* const memMgr = 0
, Conformance conform = Conf_RFC2045
);
static bool isData(const XMLByte& octet);
static bool isPad(const XMLByte& octet);
static XMLByte set1stOctet(const XMLByte&, const XMLByte&);
static XMLByte set2ndOctet(const XMLByte&, const XMLByte&);
static XMLByte set3rdOctet(const XMLByte&, const XMLByte&);
static void split1stOctet(const XMLByte&, XMLByte&, XMLByte&);
static void split2ndOctet(const XMLByte&, XMLByte&, XMLByte&);
static void split3rdOctet(const XMLByte&, XMLByte&, XMLByte&);
// -----------------------------------------------------------------------
// Unimplemented constructors and operators
// -----------------------------------------------------------------------
Base64();
Base64(const Base64&);
// -----------------------------------------------------------------------
// Private data members
//
// base64Alphabet
// The Base64 alphabet (see RFC 2045).
//
// base64Padding
// Padding character (see RFC 2045).
//
// base64Inverse
// Table used in decoding base64.
//
// isInitialized
// Set once base64Inverse is initialized.
//
// quadsPerLine
// Number of quadruplets per one line. The encoded output
// stream must be represented in lines of no more
// than 19 quadruplets each.
//
// -----------------------------------------------------------------------
static const XMLByte base64Alphabet[];
static const XMLByte base64Padding;
static const XMLByte base64Inverse[];
static const unsigned int quadsPerLine;
};
// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
inline bool Base64::isPad(const XMLByte& octet)
{
return ( octet == base64Padding );
}
inline XMLByte Base64::set1stOctet(const XMLByte& b1, const XMLByte& b2)
{
return (( b1 << 2 ) | ( b2 >> 4 ));
}
inline XMLByte Base64::set2ndOctet(const XMLByte& b2, const XMLByte& b3)
{
return (( b2 << 4 ) | ( b3 >> 2 ));
}
inline XMLByte Base64::set3rdOctet(const XMLByte& b3, const XMLByte& b4)
{
return (( b3 << 6 ) | b4 );
}
inline void Base64::split1stOctet(const XMLByte& ch, XMLByte& b1, XMLByte& b2) {
b1 = ch >> 2;
b2 = ( ch & 0x3 ) << 4;
}
inline void Base64::split2ndOctet(const XMLByte& ch, XMLByte& b2, XMLByte& b3) {
b2 |= ch >> 4; // combine with previous value
b3 = ( ch & 0xf ) << 2;
}
inline void Base64::split3rdOctet(const XMLByte& ch, XMLByte& b3, XMLByte& b4) {
b3 |= ch >> 6; // combine with previous value
b4 = ( ch & 0x3f );
}
XERCES_CPP_NAMESPACE_END
#endif
|