diff options
Diffstat (limited to 'src/base64.cc')
-rw-r--r-- | src/base64.cc | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/src/base64.cc b/src/base64.cc index 5b182b2..1cbac91 100644 --- a/src/base64.cc +++ b/src/base64.cc @@ -1,22 +1,23 @@ -/** -------------------------------------------------------------------- +/** * @file base64.cc * @brief Implementation of base64 Utilities * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "base64.h" #include <iostream> #include <string> -using namespace ::std; +using std::string; -typedef unsigned char bbyte; /* Byte type */ +typedef unsigned char bbyte; // Byte type #define TRUE 1 #define FALSE 0 -#define LINELEN 72 /* Encoded line length (max 76) */ +#define LINELEN 72 // Encoded line length (max 76) static bbyte dtable[256]; @@ -25,15 +26,14 @@ string Binc::base64encode(const string &s_in) int i; string result; - /* Fill dtable with character encodings. */ + // Fill dtable with character encodings. for (i = 0; i < 26; i++) { dtable[i] = 'A' + i; dtable[26 + i] = 'a' + i; } - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) dtable[52 + i] = '0' + i; - } dtable[62] = '+'; dtable[63] = '/'; @@ -45,23 +45,22 @@ string Binc::base64encode(const string &s_in) igroup[0] = igroup[1] = igroup[2] = 0; for (n = 0; n < 3 && s_i != s_in.end(); n++) { c = *s_i++; - igroup[n] = (bbyte)c; + igroup[n] = static_cast<bbyte>(c); } + if (n > 0) { ogroup[0] = dtable[igroup[0] >> 2]; ogroup[1] = dtable[((igroup[0] & 3) << 4) | (igroup[1] >> 4)]; ogroup[2] = dtable[((igroup[1] & 0xF) << 2) | (igroup[2] >> 6)]; ogroup[3] = dtable[igroup[2] & 0x3F]; - /* Replace characters in output stream with "=" pad - characters if fewer than three characters were - read from the end of the input stream. */ + // Replace characters in output stream with "=" pad + // characters if fewer than three characters were + // read from the end of the input stream. if (n < 3) { ogroup[3] = '='; - if (n < 2) { - ogroup[2] = '='; - } + if (n < 2) ogroup[2] = '='; } for (i = 0; i < 4; i++) @@ -77,18 +76,14 @@ string Binc::base64decode(const string &s_in) string result; int i; - for (i = 0; i < 255; i++) { + for (i = 0; i < 255; i++) dtable[i] = 0x80; - } - for (i = 'A'; i <= 'Z'; i++) { + for (i = 'A'; i <= 'Z'; i++) dtable[i] = 0 + (i - 'A'); - } - for (i = 'a'; i <= 'z'; i++) { + for (i = 'a'; i <= 'z'; i++) dtable[i] = 26 + (i - 'a'); - } - for (i = '0'; i <= '9'; i++) { + for (i = '0'; i <= '9'; i++) dtable[i] = 52 + (i - '0'); - } dtable[(int)'+'] = 62; dtable[(int)'/'] = 63; dtable[(int)'='] = 0; |