Hexadecimal functions

int eth_is_hex(const char *str, int len)

Checks whether the given string is hex or not.

Parameters
  • str[in] Target string to check

  • len[in] Length of the input string (-1 if the string is NUL-terminated)

Returns

1 when the input is valid hex, -1 otherwise

int eth_hex_pad_left(char *dest, const char *str, int len, size_t width)

Left pads the hexadecimal input.

Parameters
  • dest[in] String to write the result to

  • str[in] Original hexadecimal value

  • len[in] Length of the input string (-1 if the string is NUL-terminated)

  • width[in] Total width of the output

Returns

1 on success, -1 otherwise

int eth_hex_pad_right(char *dest, const char *str, int len, size_t width)

Right pads the hexadecimal input.

Parameters
  • dest[in] String to write the result to

  • str[in] Original hexadecimal value

  • len[in] Length of the input string (-1 if the string is NUL-terminated)

  • width[in] Total width of the output

Returns

1 on success, -1 otherwise

int eth_hex_from_bytes(char **dest, const uint8_t *bytes, size_t len)

Converts bytes to hexadecimal string.

Parameters
  • dest[in] String to write the result to

  • bytes[in] Bytes to read the data from

  • len[in] Length of the input bytes

Returns

1 on success, -1 otherwise

int eth_hex_to_bytes(uint8_t **dest, const char *hex, int hlen)

Converts hexadecimal string to bytes.

Parameters
  • dest[in] Bytes to write the data to

  • hex[in] Hexadecimal string to read the data from

  • hlen[in] Length of hexadecimal input string

Returns

1 on success, -1 otherwise