diff options
Diffstat (limited to 'src/common.c')
-rw-r--r-- | src/common.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/common.c b/src/common.c index 0c2844d82d..9bd68c2631 100644 --- a/src/common.c +++ b/src/common.c @@ -53,7 +53,7 @@ const char str_unknown[] = "(unknown)"; -/* Hex encodes the given data. +/* Hex encodes the given data adding a semicolon between hex bytes. */ const char *raw_to_string(const unsigned char *raw, size_t raw_size) { @@ -74,6 +74,26 @@ const char *raw_to_string(const unsigned char *raw, size_t raw_size) return buf; } +/* Hex encodes the given data. + */ +const char *raw_to_hex(const unsigned char *raw, size_t raw_size) +{ + static char buf[1024]; + size_t i; + if (raw_size == 0) + return "(empty)"; + + if (raw_size * 2 + 1 >= sizeof(buf)) + return "(too large)"; + + for (i = 0; i < raw_size; i++) { + sprintf(&(buf[i * 2]), "%02x", raw[i]); + } + buf[sizeof(buf) - 1] = '\0'; + + return buf; +} + const char *raw_to_base64(const unsigned char *raw, size_t raw_size) { static char buf[1024]; |