#include <Base64.h>
Collaboration diagram for Base64Decoder:

Public Member Functions | |
| Base64Decoder (Connection *conn) | |
| int | Decode (int len, const char *data, int *blen, char **buf) |
| int | Done (int *pblen, char **pbuf) |
| int | HasData () const |
| int | Errored () const |
| const char * | ErrorMsg () const |
| void | IllegalEncoding (const char *msg) |
Protected Attributes | |
| char | error_msg [256] |
| char | base64_group [4] |
| int | base64_group_next |
| int | base64_padding |
| int | base64_after_padding |
| int | errored |
| Connection * | conn |
|
|
Definition at line 34 of file Base64.cc. References base64_after_padding, base64_group_next, base64_padding, conn, errored, and init_base64_table().
00035 {
00036 init_base64_table();
00037 base64_group_next = 0;
00038 base64_padding = base64_after_padding = 0;
00039 errored = 0;
00040 conn = arg_conn;
00041 }
|
|
||||||||||||||||||||
|
Definition at line 43 of file Base64.cc. References base64_after_padding, base64_group, base64_group_next, base64_padding, base64_table, errored, fmt(), IllegalEncoding(), int, internal_error(), len, and uint32. Referenced by decode_base64(), MIME_Entity::DecodeBase64(), and Done().
00044 {
00045 int blen;
00046 char* buf;
00047
00048 if ( ! pbuf )
00049 internal_error("nil pointer to decoding result buffer");
00050
00051 if ( *pbuf )
00052 {
00053 buf = *pbuf;
00054 blen = *pblen;
00055 }
00056 else
00057 {
00058 // Estimate the maximal number of 3-byte groups needed,
00059 // plus 1 byte for the optional ending NUL.
00060 blen = int((len + base64_group_next + 3) / 4) * 3 + 1;
00061 *pbuf = buf = new char[blen];
00062 }
00063
00064 int dlen = 0;
00065
00066 while ( 1 )
00067 {
00068 if ( base64_group_next == 4 )
00069 {
00070 // For every group of 4 6-bit numbers,
00071 // write the decoded 3 bytes to the buffer.
00072 if ( base64_after_padding )
00073 {
00074 if ( ++errored == 1 )
00075 IllegalEncoding("extra base64 groups after '=' padding are ignored");
00076 base64_group_next = 0;
00077 continue;
00078 }
00079
00080 int num_octets = 3 - base64_padding;
00081
00082 if ( buf + num_octets > *pbuf + blen )
00083 break;
00084
00085 uint32 bit32 =
00086 ((base64_group[0] & 0x3f) << 18) |
00087 ((base64_group[1] & 0x3f) << 12) |
00088 ((base64_group[2] & 0x3f) << 6) |
00089 ((base64_group[3] & 0x3f));
00090
00091 if ( --num_octets >= 0 )
00092 *buf++ = char((bit32 >> 16) & 0xff);
00093
00094 if ( --num_octets >= 0 )
00095 *buf++ = char((bit32 >> 8) & 0xff);
00096
00097 if ( --num_octets >= 0 )
00098 *buf++ = char((bit32) & 0xff);
00099
00100 if ( base64_padding > 0 )
00101 base64_after_padding = 1;
00102
00103 base64_group_next = 0;
00104 base64_padding = 0;
00105 }
00106
00107 if ( dlen >= len )
00108 break;
00109
00110 if ( data[dlen] == '=' )
00111 ++base64_padding;
00112
00113 int k = base64_table[(unsigned char) data[dlen]];
00114 if ( k >= 0 )
00115 base64_group[base64_group_next++] = k;
00116 else
00117 {
00118 if ( ++errored == 1 )
00119 IllegalEncoding(fmt("character %d ignored by Base64 decoding", (int) (data[dlen])));
00120 }
00121
00122 ++dlen;
00123 }
00124
00125 *pblen = buf - *pbuf;
00126 return dlen;
00127 }
|
|
||||||||||||
|
Definition at line 129 of file Base64.cc. References base64_group_next, Decode(), fmt(), and IllegalEncoding(). Referenced by decode_base64(), and MIME_Entity::FinishDecodeBase64().
00130 {
00131 const char* padding = "===";
00132
00133 if ( base64_group_next != 0 )
00134 {
00135 if ( base64_group_next < 4 )
00136 IllegalEncoding(fmt("incomplete base64 group, padding with %d bits of 0", (4-base64_group_next) * 6));
00137 Decode(4 - base64_group_next, padding, pblen, pbuf);
00138 return -1;
00139 }
00140
00141 if ( pblen )
00142 *pblen = 0;
00143
00144 return 0;
00145 }
|
|
|
Definition at line 39 of file Base64.h. References errored.
00039 { return errored; }
|
|
|
Definition at line 41 of file Base64.h. References error_msg.
00041 { return error_msg; }
|
|
|
Definition at line 36 of file Base64.h. References base64_group_next.
00036 { return base64_group_next != 0; }
|
|
|
Definition at line 42 of file Base64.h. References conn, run_time(), and Connection::Weird(). Referenced by Decode(), and Done().
|
|
|
Definition at line 58 of file Base64.h. Referenced by Base64Decoder(), and Decode(). |
|
|
Definition at line 55 of file Base64.h. Referenced by Decode(). |
|
|
Definition at line 56 of file Base64.h. Referenced by Base64Decoder(), Decode(), Done(), and HasData(). |
|
|
Definition at line 57 of file Base64.h. Referenced by Base64Decoder(), and Decode(). |
|
|
Definition at line 60 of file Base64.h. Referenced by Base64Decoder(), and IllegalEncoding(). |
|
|
Definition at line 52 of file Base64.h. Referenced by ErrorMsg(). |
|
|
Definition at line 59 of file Base64.h. Referenced by Base64Decoder(), Decode(), and Errored(). |
1.3.5