encode.h
Go to the documentation of this file.
1 // :mode=c++:
2 /*
3 encode.h - c++ wrapper for a base64 encoding 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_ENCODE_H
9 #define BASE64_ENCODE_H
10 
11 #include "xmlrpcpp/XmlRpcDecl.h"
12 
13 #include <iostream>
14 
15 namespace base64
16 {
17  extern "C"
18  {
19  #include "cencode.h"
20  }
21 
23  {
26 
27  encoder(int buffersize_in = 512)
28  : _buffersize(buffersize_in)
29  {
30  base64_init_encodestate(&_state);
31  }
32 
33  int encode(char value_in)
34  {
35  return base64_encode_value(value_in);
36  }
37 
38  int encode(const char* code_in, const int length_in, char* plaintext_out)
39  {
40  return base64_encode_block(code_in, length_in, plaintext_out, &_state);
41  }
42 
43  int encode_end(char* plaintext_out)
44  {
45  return base64_encode_blockend(plaintext_out, &_state);
46  }
47 
48  void encode(std::istream& istream_in, std::ostream& ostream_in)
49  {
50  base64_init_encodestate(&_state);
51  //
52  const int N = _buffersize;
53  char* plaintext = new char[N];
54  char* code = new char[2*N];
55  int plainlength;
56  int codelength;
57 
58  do
59  {
60  istream_in.read(plaintext, N);
61  plainlength = istream_in.gcount();
62  //
63  codelength = encode(plaintext, plainlength, code);
64  ostream_in.write(code, codelength);
65  }
66  while (istream_in.good() && plainlength > 0);
67 
68  codelength = encode_end(code);
69  ostream_in.write(code, codelength);
70  //
71  base64_init_encodestate(&_state);
72 
73  delete [] code;
74  delete [] plaintext;
75  }
76  };
77 
78 } // namespace base64
79 
80 #endif // BASE64_ENCODE_H
81 
void base64_init_encodestate(base64_encodestate *state_in)
int encode_end(char *plaintext_out)
Definition: encode.h:43
char base64_encode_value(char value_in)
Definition: cencode.c:19
base64_encodestate _state
Definition: encode.h:24
encoder(int buffersize_in=512)
Definition: encode.h:27
int encode(const char *code_in, const int length_in, char *plaintext_out)
Definition: encode.h:38
int encode(char value_in)
Definition: encode.h:33
void encode(std::istream &istream_in, std::ostream &ostream_in)
Definition: encode.h:48
int _buffersize
Definition: encode.h:25
#define XMLRPCPP_DECL
Definition: XmlRpcDecl.h:52
int base64_encode_block(const char *plaintext_in, int length_in, char *code_out, base64_encodestate *state_in)
int base64_encode_blockend(char *code_out, base64_encodestate *state_in)
Definition: decode.h:15


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