MongoDB C++ Driver legacy-1.1.2
Loading...
Searching...
No Matches
base64.h
1// util/base64.h
2
3/* Copyright 2009 10gen Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * 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#pragma once
19
20#include <cstring>
21#include <iosfwd>
22#include <string>
23
24#include <boost/scoped_array.hpp>
25
26namespace mongo {
27namespace base64 {
28
29class Alphabet {
30public:
31 Alphabet()
32 : encode((unsigned char*)
33 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34 "abcdefghijklmnopqrstuvwxyz"
35 "0123456789"
36 "+/")
37 , decode(new unsigned char[257]) {
38 memset(decode.get(), 0, 256);
39 for (int i = 0; i < 64; i++) {
40 decode[encode[i]] = i;
41 }
42
43 test();
44 }
45
46 void test();
47
48 char e(int x) {
49 return encode[x & 0x3f];
50 }
51
52private:
53 const unsigned char* encode;
54
55public:
56 boost::scoped_array<unsigned char> decode;
57};
58
59extern Alphabet alphabet;
60
61
62void encode(std::stringstream& ss, const char* data, int size);
63std::string encode(const char* data, int size);
64std::string encode(const std::string& s);
65
66void decode(std::stringstream& ss, const std::string& s);
67std::string decode(const std::string& s);
68
69extern const char* chars;
70
71void testAlphabet();
72}
73}
Definition base64.h:29
Utility functions for parsing numbers from strings.
Definition compare_numbers.h:20