mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-01 20:52:05 -04:00
fixed bad signature checking code for config files
This commit is contained in:
parent
6c4d1c34e3
commit
4de0498208
4 changed files with 50 additions and 12 deletions
|
@ -104,6 +104,33 @@ std::string RsUtil::HashId(const std::string &id, bool reverse)
|
|||
return hash;
|
||||
}
|
||||
|
||||
static int toHalfByte(char u,bool& ok)
|
||||
{
|
||||
if(u >= 'a' && u <= 'f') return u-'a' + 0xa;
|
||||
if(u >= 'A' && u <= 'F') return u-'A' + 0xa;
|
||||
if(u >= '0' && u <= '9') return u-'0' + 0x0;
|
||||
|
||||
ok = false ;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool RsUtil::HexToBin(const std::string& input,unsigned char *data, const uint32_t len)
|
||||
{
|
||||
if(input.size() & 1)
|
||||
return false ;
|
||||
|
||||
if(len != input.size()/2)
|
||||
return false ;
|
||||
|
||||
bool ok = true ;
|
||||
|
||||
for(uint32_t i=0;(i<len) && ok;++i)
|
||||
data[i] = (toHalfByte(input[2*i],ok) << 4) + (toHalfByte(input[2*i+1],ok));
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
//static double getCurrentTS()
|
||||
//{
|
||||
//#ifndef WINDOWS_SYS
|
||||
|
|
|
@ -34,6 +34,7 @@ std::string BinToHex(const char *arr, const uint32_t len);
|
|||
// proxy function. When max_len>0 and len>max_len, only the first "max_len" bytes are writen to the string and "..." is happened.
|
||||
|
||||
std::string BinToHex(const unsigned char *arr, const uint32_t len, uint32_t max_len=0);
|
||||
bool HexToBin(const std::string& input,unsigned char *data, const uint32_t len);
|
||||
std::string NumberToString(uint64_t n, bool hex=false);
|
||||
std::string HashId(const std::string &id, bool reverse = false);
|
||||
std::vector<uint8_t> BinToSha256(const std::vector<uint8_t> &in);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue