diff options
author | laanwj <126646+laanwj@users.noreply.github.com> | 2022-05-20 10:47:26 +0200 |
---|---|---|
committer | laanwj <126646+laanwj@users.noreply.github.com> | 2022-05-20 10:47:30 +0200 |
commit | 0cd1a2eff9e0020ec1052a931f3863794d1a95d9 (patch) | |
tree | 2a0c7752c4ce28de64a02b37a6812b20c9efae05 /src/util/strencodings.cpp | |
parent | a7e3afb22136367a236f1fbc6e30b43b6b366471 (diff) | |
parent | facd1fb911abfc595a3484ee53397eff515d4c40 (diff) | |
download | bitcoin-0cd1a2eff9e0020ec1052a931f3863794d1a95d9.tar.xz |
Merge bitcoin/bitcoin#23595: util: Add ParseHex<std::byte>() helper
facd1fb911abfc595a3484ee53397eff515d4c40 refactor: Use Span of std::byte in CExtKey::SetSeed (MarcoFalke)
fae1006019188700e0c497a63fc1550fe00ca8bb util: Add ParseHex<std::byte>() helper (MarcoFalke)
fabdf81983e2542d60542b80fb94ccb1acdd204a test: Add test for embedded null in hex string (MarcoFalke)
Pull request description:
This adds the hex->`std::byte` helper after the `std::byte`->hex helper was added in commit 9394964f6b9d1cf1220a4eca17ba18dc49ae876d
ACKs for top commit:
pk-b2:
ACK https://github.com/bitcoin/bitcoin/pull/23595/commits/facd1fb911abfc595a3484ee53397eff515d4c40
laanwj:
Code review ACK facd1fb911abfc595a3484ee53397eff515d4c40
Tree-SHA512: e2329fbdea2e580bd1618caab31f5d0e59c245a028e1236662858e621929818870b76ab6834f7ac6a46d7874dfec63f498380ad99da6efe4218f720a60e859be
Diffstat (limited to 'src/util/strencodings.cpp')
-rw-r--r-- | src/util/strencodings.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/util/strencodings.cpp b/src/util/strencodings.cpp index bcedd4f517..675fe7d2d7 100644 --- a/src/util/strencodings.cpp +++ b/src/util/strencodings.cpp @@ -77,10 +77,10 @@ bool IsHexNumber(std::string_view str) return str.size() > 0; } -std::vector<unsigned char> ParseHex(std::string_view str) +template <typename Byte> +std::vector<Byte> ParseHex(std::string_view str) { - // convert hex dump to vector - std::vector<unsigned char> vch; + std::vector<Byte> vch; auto it = str.begin(); while (it != str.end() && it + 1 != str.end()) { if (IsSpace(*it)) { @@ -90,10 +90,12 @@ std::vector<unsigned char> ParseHex(std::string_view str) auto c1 = HexDigit(*(it++)); auto c2 = HexDigit(*(it++)); if (c1 < 0 || c2 < 0) break; - vch.push_back(uint8_t(c1 << 4) | c2); + vch.push_back(Byte(c1 << 4) | Byte(c2)); } return vch; } +template std::vector<std::byte> ParseHex(std::string_view); +template std::vector<uint8_t> ParseHex(std::string_view); void SplitHostPort(std::string_view in, uint16_t& portOut, std::string& hostOut) { |