aboutsummaryrefslogtreecommitdiff
path: root/src/util/strencodings.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/strencodings.cpp')
-rw-r--r--src/util/strencodings.cpp61
1 files changed, 3 insertions, 58 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp
index 7b5ded2975..e030262a32 100644
--- a/src/util/strencodings.cpp
+++ b/src/util/strencodings.cpp
@@ -3,9 +3,11 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include <span.h>
#include <util/strencodings.h>
+#include <crypto/hex_base.h>
+#include <span.h>
+
#include <array>
#include <cassert>
#include <cstring>
@@ -36,29 +38,6 @@ std::string SanitizeString(std::string_view str, int rule)
return result;
}
-const signed char p_util_hexdigit[256] =
-{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
- -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
-
-signed char HexDigit(char c)
-{
- return p_util_hexdigit[(unsigned char)c];
-}
-
bool IsHex(std::string_view str)
{
for (char c : str) {
@@ -466,40 +445,6 @@ std::string Capitalize(std::string str)
return str;
}
-namespace {
-
-using ByteAsHex = std::array<char, 2>;
-
-constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
-{
- constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-
- std::array<ByteAsHex, 256> byte_to_hex{};
- for (size_t i = 0; i < byte_to_hex.size(); ++i) {
- byte_to_hex[i][0] = hexmap[i >> 4];
- byte_to_hex[i][1] = hexmap[i & 15];
- }
- return byte_to_hex;
-}
-
-} // namespace
-
-std::string HexStr(const Span<const uint8_t> s)
-{
- std::string rv(s.size() * 2, '\0');
- static constexpr auto byte_to_hex = CreateByteToHexMap();
- static_assert(sizeof(byte_to_hex) == 512);
-
- char* it = rv.data();
- for (uint8_t v : s) {
- std::memcpy(it, byte_to_hex[v].data(), 2);
- it += 2;
- }
-
- assert(it == rv.data() + rv.size());
- return rv;
-}
-
std::optional<uint64_t> ParseByteUnits(std::string_view str, ByteUnit default_multiplier)
{
if (str.empty()) {