mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 06:28:31 +01:00
Merge bitcoin/bitcoin#23595: util: Add ParseHex<std::byte>() helper
facd1fb911refactor: Use Span of std::byte in CExtKey::SetSeed (MarcoFalke)fae1006019util: Add ParseHex<std::byte>() helper (MarcoFalke)fabdf81983test: 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 commit9394964f6bACKs for top commit: pk-b2: ACKfacd1fb911laanwj: Code review ACKfacd1fb911Tree-SHA512: e2329fbdea2e580bd1618caab31f5d0e59c245a028e1236662858e621929818870b76ab6834f7ac6a46d7874dfec63f498380ad99da6efe4218f720a60e859be
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user