mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
util: Return empty vector on invalid hex encoding
This commit is contained in:
@@ -57,9 +57,15 @@ enum class ByteUnit : uint64_t {
|
||||
* @return A new string without unsafe chars
|
||||
*/
|
||||
std::string SanitizeString(std::string_view str, int rule = SAFE_CHARS_DEFAULT);
|
||||
/** Parse the hex string into bytes (uint8_t or std::byte). Ignores whitespace. */
|
||||
/** Parse the hex string into bytes (uint8_t or std::byte). Ignores whitespace. Returns nullopt on invalid input. */
|
||||
template <typename Byte = std::byte>
|
||||
std::optional<std::vector<Byte>> TryParseHex(std::string_view str);
|
||||
/** Like TryParseHex, but returns an empty vector on invalid input. */
|
||||
template <typename Byte = uint8_t>
|
||||
std::vector<Byte> ParseHex(std::string_view str);
|
||||
std::vector<Byte> ParseHex(std::string_view hex_str)
|
||||
{
|
||||
return TryParseHex<Byte>(hex_str).value_or(std::vector<Byte>{});
|
||||
}
|
||||
signed char HexDigit(char c);
|
||||
/* Returns true if each character in str is a hex character, and has an even
|
||||
* number of hex digits.*/
|
||||
|
||||
Reference in New Issue
Block a user