summaryrefslogtreecommitdiff
path: root/src/libknot/binary.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2013-06-28 12:59:40 +0200
committerOndřej Surý <ondrej@sury.org>2013-06-28 12:59:40 +0200
commit124965832295a277b9ca6ae9fac4f45a74a36b2a (patch)
treef299e2335863f74e0be0707f84b85211baaf2d03 /src/libknot/binary.c
parent3d2d198c71a6b844b60fa9ef68801b66bba93361 (diff)
downloadknot-upstream/1.3.0_rc3.tar.gz
New upstream version 1.3.0~rc3upstream/1.3.0_rc3
Diffstat (limited to 'src/libknot/binary.c')
-rw-r--r--src/libknot/binary.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libknot/binary.c b/src/libknot/binary.c
new file mode 100644
index 0000000..aba3560
--- /dev/null
+++ b/src/libknot/binary.c
@@ -0,0 +1,56 @@
+/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#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 size;
+ }
+
+ 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;
+}