Debian Codegraph @

protolib/include/protoBase64.h

raw
1 #ifndef _PROTO_BASE64
2 #define _PROTO_BASE64
3
4 // This class implements Base64 text encoding (and decoding) of binary data per IETF RFC 4648
5 // By default, no maximum line length is imposed on encoder output and
6 // the output is fully padded per the RFC's recommendation. However, options
7 // are provided to enforce a maximum text line length and exclude padding if desired.
8
9 #include "protoDefs.h"
10
11 class ProtoBase64
12 {
13 public:
14 // Initializes encoding/decoding tables (called automatically if user doesn't)
15 static void Init();
16
17 // Returns length (in bytes) of encoding of "numBytes" of data
18 static unsigned int ComputeEncodedSize(unsigned int numBytes,
19 unsigned int maxLineLength = 0,
20 bool includePadding = true);
21
22 // Returns length of encoded data in bytes (0 if "bufferSize" too small)
23 static unsigned int Encode(const char* inputBuffer,
24 unsigned int inputBytes,
25 char* outputBuffer,
26 unsigned int bufferSize,
27 unsigned int maxLineLength = 0,
28 bool includePadding = true);
29
30 // Returns conservative (large) estimate of decoded data for "numBytes" of base64 characters
31 static unsigned int EstimateDecodedSize(unsigned int numBytes,
32 unsigned int maxLineLength = 0);
33
34 // Returns actual size (in bytes) of decoding of base64 characters in "inputBuffer"
35 static unsigned int DetermineDecodedSize(const char* inputBuffer,
36 unsigned int inputBytes);
37
38 // Returns length of decoded data in bytes (0 if "bufferSize" too small)
39 static unsigned int Decode(const char* inputBuffer,
40 unsigned int inputBytes,
41 char* outputBuffer,
42 unsigned int bufferSize);
43
44 // TBD - Add alternative "Decode()" and "DetermineDecodedSize()" methods that can use
45 // a NULL-terminated string "inputBuffer"
46
47 private:
48 static bool initialized;
49 static const char BASE64_ENCODE[];
50 static char BASE64_DECODE[255];
51 static const char PAD64;
52
53 }; // end class ProtoBase64
54
55
56 #endif // _PROTO_BASE64