@@ -69,11 +69,11 @@ class base_blob
69
69
70
70
/* * @name Hex representation
71
71
*
72
- * The hex representation used by GetHex(), ToString(), FromHex() and
73
- * SetHexDeprecated() is unusual, since it shows bytes of the base_blob in
74
- * reverse order. For example, a 4-byte blob {0x12, 0x34, 0x56, 0x78} is
75
- * represented as "78563412" instead of the more typical "12345678"
76
- * representation that would be shown in a hex editor or used by typical
72
+ * The hex representation used by GetHex(), ToString(), and FromHex()
73
+ * is unusual, since it shows bytes of the base_blob in reverse order.
74
+ * For example, a 4-byte blob {0x12, 0x34, 0x56, 0x78} is represented
75
+ * as "78563412" instead of the more typical "12345678" representation
76
+ * that would be shown in a hex editor or used by typical
77
77
* byte-array / hex conversion functions like python's bytes.hex() and
78
78
* bytes.fromhex().
79
79
*
@@ -92,20 +92,6 @@ class base_blob
92
92
*
93
93
* @{*/
94
94
std::string GetHex () const ;
95
- /* * Unlike FromHex this accepts any invalid input, thus it is fragile and deprecated!
96
- *
97
- * - Hex numbers that don't specify enough bytes to fill the internal array
98
- * will be treated as setting the beginning of it, which corresponds to
99
- * the least significant bytes when converted to base_uint.
100
- *
101
- * - Hex numbers specifying too many bytes will have the numerically most
102
- * significant bytes (the beginning of the string) narrowed away.
103
- *
104
- * - An odd count of hex digits will result in the high bits of the leftmost
105
- * byte being zero.
106
- * "0x123" => {0x23, 0x1, 0x0, ..., 0x0}
107
- */
108
- void SetHexDeprecated (std::string_view str);
109
95
std::string ToString () const ;
110
96
/* *@}*/
111
97
@@ -158,7 +144,16 @@ std::optional<uintN_t> FromHex(std::string_view str)
158
144
{
159
145
if (uintN_t::size () * 2 != str.size () || !IsHex (str)) return std::nullopt;
160
146
uintN_t rv;
161
- rv.SetHexDeprecated (str);
147
+ unsigned char * p1 = rv.begin ();
148
+ unsigned char * pend = rv.end ();
149
+ size_t digits = str.size ();
150
+ while (digits > 0 && p1 < pend) {
151
+ *p1 = ::HexDigit (str[--digits]);
152
+ if (digits > 0 ) {
153
+ *p1 |= ((unsigned char )::HexDigit (str[--digits]) << 4 );
154
+ p1++;
155
+ }
156
+ }
162
157
return rv;
163
158
}
164
159
/* *
0 commit comments