X-Git-Url: https://git.novaco.in/?a=blobdiff_plain;f=src%2Futil.h;h=0f08df84342a6717614f2d28aa90fc7fcaf3451f;hb=8ed1f8522b08e8b9811c9c16284a9967d62fb07f;hp=83a401271ad51d51b3efc8f71ba71abdfd084900;hpb=2b4717a6032cab8dad3c85daa4ccc4b60ecf932c;p=novacoin.git diff --git a/src/util.h b/src/util.h index 83a4012..0f08df8 100644 --- a/src/util.h +++ b/src/util.h @@ -11,9 +11,8 @@ #include #include #include -#else -typedef int pid_t; /* define for Windows compatibility */ #endif + #include #include #include @@ -35,7 +34,6 @@ typedef unsigned long long uint64; static const int64 COIN = 1000000; static const int64 CENT = 10000; -#define loop for (;;) #define BEGIN(a) ((char*)&(a)) #define END(a) ((char*)&((&(a))[1])) #define UBEGIN(a) ((unsigned char*)&(a)) @@ -206,6 +204,10 @@ std::vector DecodeBase32(const char* p, bool* pfInvalid = NULL); std::string DecodeBase32(const std::string& str); std::string EncodeBase32(const unsigned char* pch, size_t len); std::string EncodeBase32(const std::string& str); +std::string EncodeDumpTime(int64 nTime); +int64 DecodeDumpTime(const std::string& s); +std::string EncodeDumpString(const std::string &str); +std::string DecodeDumpString(const std::string &str); void ParseParameters(int argc, const char*const argv[]); bool WildcardMatch(const char* psz, const char* mask); bool WildcardMatch(const std::string& str, const std::string& mask); @@ -216,7 +218,9 @@ boost::filesystem::path GetDefaultDataDir(); const boost::filesystem::path &GetDataDir(bool fNetSpecific = true); boost::filesystem::path GetConfigFile(); boost::filesystem::path GetPidFile(); +#ifndef WIN32 void CreatePidFile(const boost::filesystem::path &path, pid_t pid); +#endif void ReadConfigFile(std::map& mapSettingsRet, std::map >& mapMultiSettingsRet); #ifdef WIN32 boost::filesystem::path GetSpecialFolderPath(int nFolder, bool fCreate = true); @@ -290,6 +294,16 @@ inline int64 abs64(int64 n) return (n >= 0 ? n : -n); } +inline std::string leftTrim(std::string src, char chr) +{ + std::string::size_type pos = src.find_first_not_of(chr, 0); + + if(pos > 0) + src.erase(0, pos); + + return src; +} + template std::string HexStr(const T itbegin, const T itend, bool fSpaces=false) { @@ -531,6 +545,20 @@ inline uint160 Hash160(const std::vector& vch) return hash2; } +/** + * Timing-attack-resistant comparison. + * Takes time proportional to length + * of first argument. + */ +template +bool TimingResistantEqual(const T& a, const T& b) +{ + if (b.size() == 0) return a.size() == 0; + size_t accumulator = a.size() ^ b.size(); + for (size_t i = 0; i < a.size(); i++) + accumulator |= a[i] ^ b[i%b.size()]; + return accumulator == 0; +} /** Median filter over a stream of values. * Returns the median of the last N numbers