Commit 605149fb authored by Jan Včelák's avatar Jan Včelák 🚀

libknot: add interface for manipulation with binary data with base64 conversion

refs #2353
parent 16341786
......@@ -8,6 +8,8 @@ KNOWN_ISSUES
README
tests/querytcp.c
src/libknot/libknot.h
src/libknot/binary.h
src/libknot/binary.c
src/libknot/common.h
src/libknot/dname.h
src/libknot/dname.c
......
......@@ -188,6 +188,8 @@ libknot_la_SOURCES = \
libknot/tsig.c \
libknot/tsig-op.h \
libknot/tsig-op.c \
libknot/binary.h \
libknot/binary.c \
libknot/sign/key.h \
libknot/sign/key.c
......
......@@ -14,4 +14,41 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <string.h>
#include "binary.h"
#include "common/base64.h"
#include "common/errcode.h"
int knot_binary_from_base64(const char *base64, knot_binary_t *binary)
{
if (!binary)
return KNOT_EINVAL;
uint8_t *data;
int32_t size;
size = base64_decode_alloc((uint8_t *)base64, strlen(base64), &data);
if (size < 0)
return KNOT_ENOMEM;
binary->data = data;
binary->size = size;
return KNOT_EOK;
}
int knot_binary_free(knot_binary_t *binary)
{
if (!binary)
return KNOT_EINVAL;
if (binary->data) {
free(binary->data);
binary->data = NULL;
binary->size = 0;
}
return KNOT_EOK;
}
......@@ -28,4 +28,21 @@ struct knot_binary {
typedef struct knot_binary knot_binary_t;
/*!
* \brief Initialize knot_binary_t structure from Base64 encoded string.
*
* \param base64 Base64 encoded input data.
* \param binary Pointer to structure to write the result into.
* \return Error code, KNOT_EOK in case of success.
*/
int knot_binary_from_base64(const char *base64, knot_binary_t *binary);
/*!
* \brief Free content of knot_binary_t structure.
*
* \param binary Pointer to the structure.
* \return Error code, KNOT_EOK in case of success.
*/
int knot_binary_free(knot_binary_t *binary);
#endif // _KNOT_BINARY_H
Markdown is supported
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