MongoDB C++ Driver legacy-1.0.5
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 {
27 namespace base64 {
28
29 class Alphabet {
30 public:
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
52 private:
53 const unsigned char * encode;
54 public:
55 boost::scoped_array<unsigned char> decode;
56 };
57
58 extern Alphabet alphabet;
59
60
61 void encode( std::stringstream& ss , const char * data , int size );
62 std::string encode( const char * data , int size );
63 std::string encode( const std::string& s );
64
65 void decode( std::stringstream& ss , const std::string& s );
66 std::string decode( const std::string& s );
67
68 extern const char* chars;
69
70 void testAlphabet();
71 }
72}
Definition base64.h:29
the main MongoDB namespace
Definition bulk_operation_builder.h:24