mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-16 11:53:07 +02:00
util: remove unused IsHexNumber
The relevant unit tests have been incorporated in uint256_tests/from_user_hex in a previous commit.
This commit is contained in:
parent
8a44d7d3c1
commit
2e58fdb544
@ -27,7 +27,6 @@ FUZZ_TARGET(hex)
|
|||||||
if (IsHex(random_hex_string)) {
|
if (IsHex(random_hex_string)) {
|
||||||
assert(ToLower(random_hex_string) == hex_data);
|
assert(ToLower(random_hex_string) == hex_data);
|
||||||
}
|
}
|
||||||
(void)IsHexNumber(random_hex_string);
|
|
||||||
if (uint256::FromHex(random_hex_string)) {
|
if (uint256::FromHex(random_hex_string)) {
|
||||||
assert(random_hex_string.length() == 64);
|
assert(random_hex_string.length() == 64);
|
||||||
assert(Txid::FromHex(random_hex_string));
|
assert(Txid::FromHex(random_hex_string));
|
||||||
|
@ -432,31 +432,6 @@ BOOST_AUTO_TEST_CASE(util_IsHex)
|
|||||||
BOOST_CHECK(!IsHex("0x0000"));
|
BOOST_CHECK(!IsHex("0x0000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_IsHexNumber)
|
|
||||||
{
|
|
||||||
BOOST_CHECK(IsHexNumber("0x0"));
|
|
||||||
BOOST_CHECK(IsHexNumber("0"));
|
|
||||||
BOOST_CHECK(IsHexNumber("0x10"));
|
|
||||||
BOOST_CHECK(IsHexNumber("10"));
|
|
||||||
BOOST_CHECK(IsHexNumber("0xff"));
|
|
||||||
BOOST_CHECK(IsHexNumber("ff"));
|
|
||||||
BOOST_CHECK(IsHexNumber("0xFfa"));
|
|
||||||
BOOST_CHECK(IsHexNumber("Ffa"));
|
|
||||||
BOOST_CHECK(IsHexNumber("0x00112233445566778899aabbccddeeffAABBCCDDEEFF"));
|
|
||||||
BOOST_CHECK(IsHexNumber("00112233445566778899aabbccddeeffAABBCCDDEEFF"));
|
|
||||||
|
|
||||||
BOOST_CHECK(!IsHexNumber("")); // empty string not allowed
|
|
||||||
BOOST_CHECK(!IsHexNumber("0x")); // empty string after prefix not allowed
|
|
||||||
BOOST_CHECK(!IsHexNumber("0x0 ")); // no spaces at end,
|
|
||||||
BOOST_CHECK(!IsHexNumber(" 0x0")); // or beginning,
|
|
||||||
BOOST_CHECK(!IsHexNumber("0x 0")); // or middle,
|
|
||||||
BOOST_CHECK(!IsHexNumber(" ")); // etc.
|
|
||||||
BOOST_CHECK(!IsHexNumber("0x0ga")); // invalid character
|
|
||||||
BOOST_CHECK(!IsHexNumber("x0")); // broken prefix
|
|
||||||
BOOST_CHECK(!IsHexNumber("0x0x00")); // two prefixes not allowed
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
|
BOOST_AUTO_TEST_CASE(util_seed_insecure_rand)
|
||||||
{
|
{
|
||||||
SeedRandomForTest(SeedRand::ZEROS);
|
SeedRandomForTest(SeedRand::ZEROS);
|
||||||
|
@ -46,16 +46,6 @@ bool IsHex(std::string_view str)
|
|||||||
return (str.size() > 0) && (str.size()%2 == 0);
|
return (str.size() > 0) && (str.size()%2 == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsHexNumber(std::string_view str)
|
|
||||||
{
|
|
||||||
if (str.substr(0, 2) == "0x") str.remove_prefix(2);
|
|
||||||
for (char c : str) {
|
|
||||||
if (HexDigit(c) < 0) return false;
|
|
||||||
}
|
|
||||||
// Return false for empty string or "0x".
|
|
||||||
return str.size() > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename Byte>
|
template <typename Byte>
|
||||||
std::optional<std::vector<Byte>> TryParseHex(std::string_view str)
|
std::optional<std::vector<Byte>> TryParseHex(std::string_view str)
|
||||||
{
|
{
|
||||||
|
@ -70,10 +70,6 @@ std::vector<Byte> ParseHex(std::string_view hex_str)
|
|||||||
/* Returns true if each character in str is a hex character, and has an even
|
/* Returns true if each character in str is a hex character, and has an even
|
||||||
* number of hex digits.*/
|
* number of hex digits.*/
|
||||||
bool IsHex(std::string_view str);
|
bool IsHex(std::string_view str);
|
||||||
/**
|
|
||||||
* Return true if the string is a hex number, optionally prefixed with "0x"
|
|
||||||
*/
|
|
||||||
bool IsHexNumber(std::string_view str);
|
|
||||||
std::optional<std::vector<unsigned char>> DecodeBase64(std::string_view str);
|
std::optional<std::vector<unsigned char>> DecodeBase64(std::string_view str);
|
||||||
std::string EncodeBase64(Span<const unsigned char> input);
|
std::string EncodeBase64(Span<const unsigned char> input);
|
||||||
inline std::string EncodeBase64(Span<const std::byte> input) { return EncodeBase64(MakeUCharSpan(input)); }
|
inline std::string EncodeBase64(Span<const std::byte> input) { return EncodeBase64(MakeUCharSpan(input)); }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user