44 */
55#include <aws/http/private/strutil.h>
66
7- /* Lookup from '0' -> 0, 'f' -> 0xf, 'F' -> 0xF, etc
8- * invalid characters have value 255 */
9- /* clang-format off */
10- static const uint8_t s_ascii_to_num_table [256 ] = {
11- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
12- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
13- 255 , 255 ,
14- /* 0 - 9 */
15- 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ,
16- 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
17- /* A - F */
18- 0xA , 0xB , 0xC , 0xD , 0xE , 0xF ,
19- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
20- 255 , 255 , 255 ,
21- /* a - f */
22- 0xa , 0xb , 0xc , 0xd , 0xe , 0xf ,
23- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
24- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
25- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
26- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
27- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
28- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
29- 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 , 255 ,
30- };
31- /* clang-format on */
32-
337static int s_read_unsigned (struct aws_byte_cursor cursor , uint64_t * dst , uint8_t base ) {
348 uint64_t val = 0 ;
359 * dst = 0 ;
@@ -38,10 +12,12 @@ static int s_read_unsigned(struct aws_byte_cursor cursor, uint64_t *dst, uint8_t
3812 return aws_raise_error (AWS_ERROR_INVALID_ARGUMENT );
3913 }
4014
15+ const uint8_t * hex_to_num_table = aws_lookup_table_hex_to_num_get ();
16+
4117 /* read from left to right */
4218 for (size_t i = 0 ; i < cursor .len ; ++ i ) {
4319 const uint8_t c = cursor .ptr [i ];
44- const uint8_t cval = s_ascii_to_num_table [c ];
20+ const uint8_t cval = hex_to_num_table [c ];
4521 if (cval >= base ) {
4622 return aws_raise_error (AWS_ERROR_INVALID_ARGUMENT );
4723 }
0 commit comments