oxen-io / oxen-mq

Communications layer used for both the Oxen storage server and oxend
https://oxen.io
BSD 3-Clause "New" or "Revised" License
19 stars 37 forks source link

Make lokimq::is_hex check for size being a multiple of 2 #28

Closed jagerman closed 3 years ago

jagerman commented 3 years ago

is_hex() is a bit misleading as from_hex() requires an even-length hex string, but is_hex() also allows odd-length hex strings, which means currently callers should be doing if (lokimq::is_hex(str) && str.size() % 2 == 0), but probably aren't.

Since the main point of lokimq/hex.h is for byte<->hex conversions it doesn't make much sense to allow is_hex() to return true for something that can't be validly decoded via from_hex(), thus this PR changes it to return false.

If someone really wants to test for an odd-length hex string, this also exposes is_hex_digit so that they could use:

bool all_hex = std::all_of(str.begin(), str.end(), lokimq::is_hex_digit<char>);