HomePhabricator

Handle invalid hex encoding in ParseHex

Description

Handle invalid hex encoding in ParseHex

Summary:
Seems a bit confusing to happily accept random bytes and pretend they are hex encoded strings

Added a new TryParseHex function returning an optional. The old function remains an alias, with the fallback to an empty vector. This avoid having to change all existing code and making it needlessly verbose, because it is already properly handling empty vectors.

This is a backport of core#25227

Fix a hex string in checkpoints_tests that was obviously wrong (odd number of hex chars) and now causes ParseHex to return an empty vector.

Depends on D17157

Test Plan: ninja all check-all

Reviewers: #bitcoin_abc, roqqit

Reviewed By: roqqit

Differential Revision: https://reviews.bitcoinabc.org/D17158

Details

Provenance
MarcoFalke <6399679+MarcoFalke@users.noreply.github.com>Authored on Feb 27 2023, 12:14
PiRKCommitted on Mon, Nov 18, 19:56
PiRKPushed on Mon, Nov 18, 19:56
Reviewer
roqqit
Differential Revision
D17158: Handle invalid hex encoding in ParseHex
Parents
rABC000b0266e7e8: util: Add ParseHex<std::byte>() helper
Branches
Unknown
Tags
Unknown

Event Timeline