Permalink
Browse files

Fix hexadecimal string generation

  • Loading branch information...
mbasaglia committed Mar 9, 2016
1 parent b8d4b72 commit 97beb6a1ad97bbd1ae465174d8b89ac3c7841968
Showing with 10 additions and 2 deletions.
  1. +10 −2 daemon/src/engine/framework/Crypto.cpp
@@ -99,6 +99,14 @@ Data RandomData( std::size_t bytes )
namespace Encoding {
/*
* Converts a value from 0 to 15 into a hexadecimal digit
*/
static char HexDigit( uint8_t digit )
{
return digit > 9 ? digit - 10 + 'a' : digit + '0';
}
/*
* Translates binary data into a hexadecimal string
*/
@@ -108,8 +116,8 @@ Data HexEncode( const Data& input )
output.reserve(input.size()*2);
for ( auto byte : input )
{
output.push_back((byte & 0xF0) >> 4);
output.push_back(byte & 0xF);
output.push_back(HexDigit((byte & 0xF0) >> 4));
output.push_back(HexDigit(byte & 0xF));
}
return output;
}

0 comments on commit 97beb6a

Please sign in to comment.