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 <iostream>
12 
13 namespace base64
14 {
15  extern "C"
16  {
17  #include "cdecode.h"
18  }
19 
20  struct decoder
21  {
24 
25  decoder(int buffersize_in = 512)
26  : _buffersize(buffersize_in)
27  {
28  base64_init_decodestate(&_state);
29  }
30 
31  int decode(char value_in)
32  {
33  return base64_decode_value(value_in);
34  }
35 
36  int decode(const char* code_in, const int length_in, char* plaintext_out)
37  {
38  return base64_decode_block(code_in, length_in, plaintext_out, &_state);
39  }
40 
41  void decode(std::istream& istream_in, std::ostream& ostream_in)
42  {
43  base64_init_decodestate(&_state);
44  //
45  const int N = _buffersize;
46  char* code = new char[N];
47  char* plaintext = new char[N];
48  int codelength;
49  int plainlength;
50 
51  do
52  {
53  istream_in.read((char*)code, N);
54  codelength = istream_in.gcount();
55  plainlength = decode(code, codelength, plaintext);
56  ostream_in.write((const char*)plaintext, plainlength);
57  }
58  while (istream_in.good() && codelength > 0);
59  //
60  base64_init_decodestate(&_state);
61 
62  delete [] code;
63  delete [] plaintext;
64  }
65  };
66 
67 } // namespace base64
68 
69 
70 
71 #endif // BASE64_DECODE_H
72 
int decode(char value_in)
Definition: decode.h:31
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:25
int _buffersize
Definition: decode.h:23
base64_decodestate _state
Definition: decode.h:22
Definition: decode.h:13
int decode(const char *code_in, const int length_in, char *plaintext_out)
Definition: decode.h:36
int base64_decode_value(char value_in)
Definition: cdecode.c:10
void decode(std::istream &istream_in, std::ostream &ostream_in)
Definition: decode.h:41


xmlrpcpp
Author(s): Chris Morley, Konstantin Pilipchuk, Morgan Quigley, Austin Hendrix
autogenerated on Sun Feb 3 2019 03:29:51