base64dec.hpp

Go to the documentation of this file.
00001 // :mode=c++:
00002 /*
00003 decode.h - c++ wrapper for a base64 decoding algorithm
00004 
00005 This is part of the libb64 project, and has been placed in the public domain.
00006 For details, see http://sourceforge.net/projects/libb64
00007 */
00008 
00009 #ifndef BASE64_DECODE_H
00010 #define BASE64_DECODE_H
00011 
00012 #include <iostream>
00013 
00014 namespace s11n
00015 {
00016 namespace base64
00017 {
00018     
00019     extern "C"
00020     {
00021         #include "base64dec.h"
00022     }
00023     
00024     struct decoder
00025     {
00026         base64_decodestate _state;
00027         int _buffersize;
00028         
00029         decoder(int buffersize_in = 4096)
00030         : _buffersize(buffersize_in)
00031         {}
00032         int decode(char value_in)
00033         {
00034             return base64_decode_value(value_in);
00035         }
00036         int decode(const char* code_in, const int length_in, char* plaintext_out)
00037         {
00038             return base64_decode_block(code_in, length_in, plaintext_out, &_state);
00039         }
00040         void decode(std::istream& istream_in, std::ostream& ostream_in)
00041         {
00042             base64_init_decodestate(&_state);
00043             //
00044             const int N = _buffersize;
00045             char* code = new char[N];
00046             char* plaintext = new char[N];
00047             int codelength;
00048             int plainlength;
00049             
00050             do
00051             {
00052                 istream_in.read((char*)code, N);
00053                 codelength = istream_in.gcount();
00054                 plainlength = decode(code, codelength, plaintext);
00055                 ostream_in.write((const char*)plaintext, plainlength);
00056             }
00057             while (istream_in.good() && codelength > 0);
00058             //
00059             base64_init_decodestate(&_state);
00060             
00061             delete [] code;
00062             delete [] plaintext;
00063         }
00064     };
00065     
00066 } // namespace base64
00067 } // namespace s11n
00068 #endif // BASE64_DECODE_H

Generated on Wed Jun 4 21:44:19 2008 for libs11n by  doxygen 1.5.3