Skip to content

Commit

Permalink
util: remove unused IsHexNumber
Browse files Browse the repository at this point in the history
The relevant unit tests have been incorporated in
uint256_tests/from_user_hex in a previous commit.
  • Loading branch information
stickies-v committed Aug 23, 2024
1 parent 8a44d7d commit 2e58fdb
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 40 deletions.
1 change: 0 additions & 1 deletion src/test/fuzz/hex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ FUZZ_TARGET(hex)
if (IsHex(random_hex_string)) {
assert(ToLower(random_hex_string) == hex_data);
}
(void)IsHexNumber(random_hex_string);
if (uint256::FromHex(random_hex_string)) {
assert(random_hex_string.length() == 64);
assert(Txid::FromHex(random_hex_string));
Expand Down
25 changes: 0 additions & 25 deletions src/test/util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,31 +432,6 @@ BOOST_AUTO_TEST_CASE(util_IsHex)
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)
{
SeedRandomForTest(SeedRand::ZEROS);
Expand Down
10 changes: 0 additions & 10 deletions src/util/strencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ bool IsHex(std::string_view str)
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>
std::optional<std::vector<Byte>> TryParseHex(std::string_view str)
{
Expand Down
4 changes: 0 additions & 4 deletions src/util/strencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* number of hex digits.*/
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::string EncodeBase64(Span<const unsigned char> input);
inline std::string EncodeBase64(Span<const std::byte> input) { return EncodeBase64(MakeUCharSpan(input)); }
Expand Down

0 comments on commit 2e58fdb

Please sign in to comment.