@ -812,10 +812,9 @@ size_t hexEncode(const uint8_t * in, size_t in_size, char * out, size_t out_size
// From an hexa char array ("A220EE...") to a byte array (half the size)
size_t hexDecode ( const char * in , size_t in_size , uint8_t * out , size_t out_size ) {
if ( out_size < ( in_size / 2 ) ) return 0 ;
size_t index = 0 ;
size_t out_index = 0 ;
if ( ( in_size & 1 ) | | ( out_size < ( in_size / 2 ) ) ) {
return 0 ;
}
auto char2byte = [ ] ( char ch ) - > uint8_t {
if ( ( ch > = ' 0 ' ) & & ( ch < = ' 9 ' ) ) {
@ -829,13 +828,22 @@ size_t hexDecode(const char* in, size_t in_size, uint8_t* out, size_t out_size)
}
} ;
while ( index < in_size ) {
out [ out_index ] = char2byte ( in [ index ] ) < < 4 ;
out [ out_index ] + = char2byte ( in [ index + 1 ] ) ;
size_t index = 0 ;
size_t out_index = 0 ;
uint8_t lhs , rhs ;
index + = 2 ;
out_index + = 1 ;
while ( index < in_size ) {
lhs = char2byte ( in [ index ] ) < < 4 ;
rhs = char2byte ( in [ index + 1 ] ) ;
if ( lhs | | rhs ) {
out [ out_index + + ] = lhs | rhs ;
index + = 2 ;
continue ;
}
out_index = 0 ;
break ;
}
return out_index ? ( 1 + out_index ) : 0 ;
return out_index ;
}