decode.h
Go to the documentation of this file.
1 // :mode=c++:
2 /*
3 decode.h - c++ wrapper for a base64 decoding algorithm
4 
5 This is part of the libb64 project, and has been placed in the public domain.
6 For details, see http://sourceforge.net/projects/libb64
7 */
8 #ifndef BASE64_DECODE_H
9 #define BASE64_DECODE_H
10 
11 #include "xmlrpcpp/XmlRpcDecl.h"
12 
13 #include <iostream>
14 
15 namespace base64
16 {
17  extern "C"
18  {
19  #include "cdecode.h"
20  }
21 
23  {
26 
27  decoder(int buffersize_in = 512)
28  : _buffersize(buffersize_in)
29  {
30  base64_init_decodestate(&_state);
31  }
32 
33  int decode(char value_in)
34  {
35  return base64_decode_value(value_in);
36  }
37 
38  int decode(const char* code_in, const int length_in, char* plaintext_out)
39  {
40  return base64_decode_block(code_in, length_in, plaintext_out, &_state);
41  }
42 
43  void decode(std::istream& istream_in, std::ostream& ostream_in)
44  {
45  base64_init_decodestate(&_state);
46  //
47  const int N = _buffersize;
48  char* code = new char[N];
49  char* plaintext = new char[N];
50  int codelength;
51  int plainlength;
52 
53  do
54  {
55  istream_in.read((char*)code, N);
56  codelength = istream_in.gcount();
57  plainlength = decode(code, codelength, plaintext);
58  ostream_in.write((const char*)plaintext, plainlength);
59  }
60  while (istream_in.good() && codelength > 0);
61  //
62  base64_init_decodestate(&_state);
63 
64  delete [] code;
65  delete [] plaintext;
66  }
67  };
68 
69 } // namespace base64
70 
71 
72 
73 #endif // BASE64_DECODE_H
74 
int decode(char value_in)
Definition: decode.h:33
int base64_decode_block(const char *code_in, const int length_in, char *plaintext_out, base64_decodestate *state_in)
void base64_init_decodestate(base64_decodestate *state_in)
decoder(int buffersize_in=512)
Definition: decode.h:27
#define XMLRPCPP_DECL
Definition: XmlRpcDecl.h:52
int _buffersize
Definition: decode.h:25
base64_decodestate _state
Definition: decode.h:24
Definition: decode.h:15
int decode(const char *code_in, const int length_in, char *plaintext_out)
Definition: decode.h:38
int base64_decode_value(char value_in)
Definition: cdecode.c:10
void decode(std::istream &istream_in, std::ostream &ostream_in)
Definition: decode.h:43


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:22