Improvements for epee binary to hex functions:

- Performance improvements
  - Added `span` for zero-copy pointer+length arguments
  - Added `std::ostream` overload for direct writing to output buffers
  - Removal of unused `string_tools::buff_to_hex`
This commit is contained in:
Lee Clagett 2017-02-27 13:33:16 -05:00
parent 9ed496bbc5
commit 4a8f96f95d
14 changed files with 767 additions and 76 deletions

View file

@ -67,6 +67,7 @@
#include <type_traits>
#include "crypto/crypto.h"
#include "hex.h"
#include "md5_l.h"
#include "string_coding.h"
@ -104,25 +105,6 @@ namespace
//// Digest Algorithms
template<std::size_t N>
std::array<char, N * 2> to_hex(const std::array<std::uint8_t, N>& digest) noexcept
{
static constexpr const char alphabet[] = u8"0123456789abcdef";
static_assert(sizeof(alphabet) == 17, "bad alphabet size");
// TODO upgrade (improve performance) of to hex in epee string tools
std::array<char, N * 2> out{{}};
auto current = out.begin();
for (const std::uint8_t byte : digest)
{
*current = alphabet[byte >> 4];
++current;
*current = alphabet[byte & 0x0F];
++current;
}
return out;
}
struct md5_
{
static constexpr const boost::string_ref name = ceref(u8"MD5");
@ -156,7 +138,7 @@ namespace
std::array<std::uint8_t, 16> digest{{}};
md5::MD5Final(digest.data(), std::addressof(ctx));
return to_hex(digest);
return epee::to_hex::array(digest);
}
};
constexpr const boost::string_ref md5_::name;