00001
00002
00003
00004
00005
00006
00007
00008 #ifndef BASE64_DECODE_H
00009 #define BASE64_DECODE_H
00010
00011 #include <iostream>
00012
00013 namespace base64
00014 {
00015 extern "C"
00016 {
00017 #include "cdecode.h"
00018 }
00019
00020 struct decoder
00021 {
00022 base64_decodestate _state;
00023 int _buffersize;
00024
00025 decoder(int buffersize_in = BUFFERSIZE)
00026 : _buffersize(buffersize_in)
00027 {}
00028
00029 int decode(char value_in)
00030 {
00031 return base64_decode_value(value_in);
00032 }
00033
00034 int decode(const char* code_in, const int length_in, char* plaintext_out)
00035 {
00036 return base64_decode_block(code_in, length_in, plaintext_out, &_state);
00037 }
00038
00039 void decode(std::istream& istream_in, std::ostream& ostream_in)
00040 {
00041 base64_init_decodestate(&_state);
00042
00043 const int N = _buffersize;
00044 char* code = new char[N];
00045 char* plaintext = new char[N];
00046 int codelength;
00047 int plainlength;
00048
00049 do
00050 {
00051 istream_in.read((char*)code, N);
00052 codelength = istream_in.gcount();
00053 plainlength = decode(code, codelength, plaintext);
00054 ostream_in.write((const char*)plaintext, plainlength);
00055 }
00056 while (istream_in.good() && codelength > 0);
00057
00058 base64_init_decodestate(&_state);
00059
00060 delete [] code;
00061 delete [] plaintext;
00062 }
00063 };
00064
00065 }
00066
00067
00068
00069 #endif // BASE64_DECODE_H
00070