Skip to content
Snippets Groups Projects
Commit 7df2a616 authored by Jan Včelák's avatar Jan Včelák :rocket:
Browse files

[dnssec] add hex_to_string() API

parent 150ff214
Branches
Tags
1 merge request!332libdnssec
......@@ -11,6 +11,8 @@ libdnssec_la_SOURCES = \
src/binary.c \
src/binary.h \
src/error.h \
src/hex.c \
src/hex.h \
src/key.c \
src/key.h \
src/keys/legacy.c \
......
#include "binary.h"
static const char BIN_TO_HEX[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
char *hex_to_string(const dnssec_binary_t *data)
{
char *str = malloc(data->size * 2 + 1);
if (!str) {
return NULL;
}
for (size_t i = 0; i < data->size; i++) {
str[2*i] = BIN_TO_HEX[data->data[i] >> 4];
str[2*i+1] = BIN_TO_HEX[data->data[i] & 0x0f];
}
str[2 * data->size] = '\0';
return str;
}
#pragma once
#include "binary.h"
char *hex_to_string(const dnssec_binary_t *data);
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment