1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
14/* This file is derived from the libb64 project which itself was released to public domain.
15 * For details, see http://sourceforge.net/projects/libb64. Original code by Chris Venter
16 * c++ wrapper for a base64 encoding and decoding algorithm
19#ifndef OSGDB_CONVERTBASE64_H
20#define OSGDB_CONVERTBASE64_H 1
26#include <osgDB/Export>
30 const int BUFFERSIZE = 8192;
34 step_a, step_b, step_c, step_d
39 step_A, step_B, step_C
44 base64_encodestep step;
49 inline void base64_init_encodestate(base64_encodestate* state_in)
51 state_in->step = step_A;
53 state_in->stepcount = 0;
59 base64_decodestep step;
63 inline void base64_init_decodestate(base64_decodestate* state_in)
65 state_in->step = step_a;
66 state_in->plainchar = 0;
69 class OSGDB_EXPORT Base64encoder
72 Base64encoder(int buffersize_in = BUFFERSIZE):
73 _buffersize(buffersize_in)
75 base64_init_encodestate(&_state);
78 int encode(char value_in);
80 int encode(const char* code_in, const int length_in, char* plaintext_out);
82 int encode_end(char* plaintext_out);
84 void encode(std::istream& istream_in, std::ostream& ostream_in);
86 void encode(const char* chars_in, int length_in, std::string& code_out);
89 base64_encodestate _state;
93 class OSGDB_EXPORT Base64decoder
96 Base64decoder(int buffersize_in = BUFFERSIZE):
97 _buffersize(buffersize_in)
99 base64_init_decodestate(&_state);
102 int decode(char value_in);
104 int decode(const char* code_in, const int length_in, char* plaintext_out);
106 void decode(std::istream& istream_in, std::ostream& ostream_in);
108 // Decode strings, returns one char* of appropriate size
109 // Note that deallocation of char* is up to the caller of this method
110 char* decode(const std::vector<std::string>& str_in, std::vector<unsigned int>& pos_out);
113 base64_decodestate _state;
119#endif // BASE64_DECODE_H