summaryrefslogtreecommitdiff
path: root/src/asc2bin.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/asc2bin.h')
-rw-r--r--src/asc2bin.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/asc2bin.h b/src/asc2bin.h
new file mode 100644
index 0000000..42c3b54
--- /dev/null
+++ b/src/asc2bin.h
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set et sw=2 ts=2: */
+/***************************************************************************
+ * asc2bin.h
+ *
+ * Thu Sep 5 11:12:50 CEST 2013
+ * Copyright 2013 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of lrtp.
+ *
+ * lrtp is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * lrtp 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with lrtp; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __LRTP_ASC2BIN_H__
+#define __LRTP_ASC2BIN_H__
+
+#include <stdlib.h>
+
+#include "compat.h"
+
+/**
+ * asc2bin converts a hexadecimal string to a raw octet string.
+ * @param raw The char buffer that will contain the result.
+ * @param rawsz The size of the output buffer 'raw'. This size must be at
+ * least hexlen / 2.
+ * @param hex The input hex string.
+ * @param hexlen The length of the hex string.
+ * @return The length of the resulting raw data. -1 on error.
+ * Errors are one of the following:
+ * - Hex string contains invalid hex character (0-9, a-f and A-F allowed).
+ * - rawsz is less than hexlen / 2.
+ * - hexlen is not a multiplum of 2 (odd hex string lengths not supported).
+ */
+ssize_t asc2bin(char *raw, size_t rawsz, const char *hex, size_t hexlen);
+
+#endif/*__LRTP_ASC2BIN_H__*/