|
|
|
@ -12,20 +12,18 @@
@@ -12,20 +12,18 @@
|
|
|
|
|
#include <errno.h> |
|
|
|
|
#include <limits> |
|
|
|
|
|
|
|
|
|
using namespace std; |
|
|
|
|
static const std::string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
|
|
|
|
|
|
|
|
|
static const string CHARS_ALPHA_NUM = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; |
|
|
|
|
|
|
|
|
|
static const string SAFE_CHARS[] = |
|
|
|
|
static const std::string SAFE_CHARS[] = |
|
|
|
|
{ |
|
|
|
|
CHARS_ALPHA_NUM + " .,;-_/:?@()", // SAFE_CHARS_DEFAULT
|
|
|
|
|
CHARS_ALPHA_NUM + " .,;-_?@", // SAFE_CHARS_UA_COMMENT
|
|
|
|
|
CHARS_ALPHA_NUM + ".-_", // SAFE_CHARS_FILENAME
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
string SanitizeString(const string& str, int rule) |
|
|
|
|
std::string SanitizeString(const std::string& str, int rule) |
|
|
|
|
{ |
|
|
|
|
string strResult; |
|
|
|
|
std::string strResult; |
|
|
|
|
for (std::string::size_type i = 0; i < str.size(); i++) |
|
|
|
|
{ |
|
|
|
|
if (SAFE_CHARS[rule].find(str[i]) != std::string::npos) |
|
|
|
@ -57,7 +55,7 @@ signed char HexDigit(char c)
@@ -57,7 +55,7 @@ signed char HexDigit(char c)
|
|
|
|
|
return p_util_hexdigit[(unsigned char)c]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool IsHex(const string& str) |
|
|
|
|
bool IsHex(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
for(std::string::const_iterator it(str.begin()); it != str.end(); ++it) |
|
|
|
|
{ |
|
|
|
@ -67,10 +65,10 @@ bool IsHex(const string& str)
@@ -67,10 +65,10 @@ bool IsHex(const string& str)
|
|
|
|
|
return (str.size() > 0) && (str.size()%2 == 0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vector<unsigned char> ParseHex(const char* psz) |
|
|
|
|
std::vector<unsigned char> ParseHex(const char* psz) |
|
|
|
|
{ |
|
|
|
|
// convert hex dump to vector
|
|
|
|
|
vector<unsigned char> vch; |
|
|
|
|
std::vector<unsigned char> vch; |
|
|
|
|
while (true) |
|
|
|
|
{ |
|
|
|
|
while (isspace(*psz)) |
|
|
|
@ -88,16 +86,16 @@ vector<unsigned char> ParseHex(const char* psz)
@@ -88,16 +86,16 @@ vector<unsigned char> ParseHex(const char* psz)
|
|
|
|
|
return vch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vector<unsigned char> ParseHex(const string& str) |
|
|
|
|
std::vector<unsigned char> ParseHex(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
return ParseHex(str.c_str()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string EncodeBase64(const unsigned char* pch, size_t len) |
|
|
|
|
std::string EncodeBase64(const unsigned char* pch, size_t len) |
|
|
|
|
{ |
|
|
|
|
static const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; |
|
|
|
|
|
|
|
|
|
string strRet=""; |
|
|
|
|
std::string strRet = ""; |
|
|
|
|
strRet.reserve((len+2)/3*4); |
|
|
|
|
|
|
|
|
|
int mode=0, left=0; |
|
|
|
@ -139,12 +137,12 @@ string EncodeBase64(const unsigned char* pch, size_t len)
@@ -139,12 +137,12 @@ string EncodeBase64(const unsigned char* pch, size_t len)
|
|
|
|
|
return strRet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string EncodeBase64(const string& str) |
|
|
|
|
std::string EncodeBase64(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
return EncodeBase64((const unsigned char*)str.c_str(), str.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid) |
|
|
|
|
std::vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid) |
|
|
|
|
{ |
|
|
|
|
static const int decode64_table[256] = |
|
|
|
|
{ |
|
|
|
@ -166,7 +164,7 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
@@ -166,7 +164,7 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
|
|
|
|
|
if (pfInvalid) |
|
|
|
|
*pfInvalid = false; |
|
|
|
|
|
|
|
|
|
vector<unsigned char> vchRet; |
|
|
|
|
std::vector<unsigned char> vchRet; |
|
|
|
|
vchRet.reserve(strlen(p)*3/4); |
|
|
|
|
|
|
|
|
|
int mode = 0; |
|
|
|
@ -227,17 +225,17 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
@@ -227,17 +225,17 @@ vector<unsigned char> DecodeBase64(const char* p, bool* pfInvalid)
|
|
|
|
|
return vchRet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string DecodeBase64(const string& str) |
|
|
|
|
std::string DecodeBase64(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
vector<unsigned char> vchRet = DecodeBase64(str.c_str()); |
|
|
|
|
return (vchRet.size() == 0) ? string() : string((const char*)&vchRet[0], vchRet.size()); |
|
|
|
|
std::vector<unsigned char> vchRet = DecodeBase64(str.c_str()); |
|
|
|
|
return (vchRet.size() == 0) ? std::string() : std::string((const char*)&vchRet[0], vchRet.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string EncodeBase32(const unsigned char* pch, size_t len) |
|
|
|
|
std::string EncodeBase32(const unsigned char* pch, size_t len) |
|
|
|
|
{ |
|
|
|
|
static const char *pbase32 = "abcdefghijklmnopqrstuvwxyz234567"; |
|
|
|
|
|
|
|
|
|
string strRet=""; |
|
|
|
|
std::string strRet=""; |
|
|
|
|
strRet.reserve((len+4)/5*8); |
|
|
|
|
|
|
|
|
|
int mode=0, left=0; |
|
|
|
@ -292,12 +290,12 @@ string EncodeBase32(const unsigned char* pch, size_t len)
@@ -292,12 +290,12 @@ string EncodeBase32(const unsigned char* pch, size_t len)
|
|
|
|
|
return strRet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string EncodeBase32(const string& str) |
|
|
|
|
std::string EncodeBase32(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
return EncodeBase32((const unsigned char*)str.c_str(), str.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid) |
|
|
|
|
std::vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid) |
|
|
|
|
{ |
|
|
|
|
static const int decode32_table[256] = |
|
|
|
|
{ |
|
|
|
@ -319,7 +317,7 @@ vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
@@ -319,7 +317,7 @@ vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
|
|
|
|
|
if (pfInvalid) |
|
|
|
|
*pfInvalid = false; |
|
|
|
|
|
|
|
|
|
vector<unsigned char> vchRet; |
|
|
|
|
std::vector<unsigned char> vchRet; |
|
|
|
|
vchRet.reserve((strlen(p))*5/8); |
|
|
|
|
|
|
|
|
|
int mode = 0; |
|
|
|
@ -414,10 +412,10 @@ vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
@@ -414,10 +412,10 @@ vector<unsigned char> DecodeBase32(const char* p, bool* pfInvalid)
|
|
|
|
|
return vchRet; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string DecodeBase32(const string& str) |
|
|
|
|
std::string DecodeBase32(const std::string& str) |
|
|
|
|
{ |
|
|
|
|
vector<unsigned char> vchRet = DecodeBase32(str.c_str()); |
|
|
|
|
return (vchRet.size() == 0) ? string() : string((const char*)&vchRet[0], vchRet.size()); |
|
|
|
|
std::vector<unsigned char> vchRet = DecodeBase32(str.c_str()); |
|
|
|
|
return (vchRet.size() == 0) ? std::string() : std::string((const char*)&vchRet[0], vchRet.size()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static bool ParsePrechecks(const std::string& str) |
|
|
|
|