[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r35045 - in gnunet/src: include util
From: |
gnunet |
Subject: |
[GNUnet-SVN] r35045 - in gnunet/src: include util |
Date: |
Wed, 28 Jan 2015 20:32:56 +0100 |
Author: grothoff
Date: 2015-01-28 20:32:56 +0100 (Wed, 28 Jan 2015)
New Revision: 35045
Modified:
gnunet/src/include/gnunet_strings_lib.h
gnunet/src/util/strings.c
Log:
add GNUNET_STRINGS_data_to_string_alloc from TALER
Modified: gnunet/src/include/gnunet_strings_lib.h
===================================================================
--- gnunet/src/include/gnunet_strings_lib.h 2015-01-28 19:23:04 UTC (rev
35044)
+++ gnunet/src/include/gnunet_strings_lib.h 2015-01-28 19:32:56 UTC (rev
35045)
@@ -297,6 +297,21 @@
/**
+ * Return the base32crockford encoding of the given buffer.
+ *
+ * The returned string will be freshly allocated, and must be free'd
+ * with #GNUNET_free().
+ *
+ * @param buffer with data
+ * @param size size of the buffer
+ * @return freshly allocated, null-terminated string
+ */
+char *
+GNUNET_STRINGS_data_to_string_alloc (const void *buf,
+ size_t size);
+
+
+/**
* Convert Base32hex encoding back to data.
* @a out_size must match exactly the size of the data before it was encoded.
*
Modified: gnunet/src/util/strings.c
===================================================================
--- gnunet/src/util/strings.c 2015-01-28 19:23:04 UTC (rev 35044)
+++ gnunet/src/util/strings.c 2015-01-28 19:32:56 UTC (rev 35045)
@@ -846,10 +846,13 @@
* @param out buffer to fill
* @param out_size size of the buffer. Must be large enough to hold
* (size * 8 + 4) / 5 bytes
- * @return pointer to the next byte in 'out' or NULL on error.
+ * @return pointer to the next byte in @a out or NULL on error.
*/
char *
-GNUNET_STRINGS_data_to_string (const void *data, size_t size, char *out,
size_t out_size)
+GNUNET_STRINGS_data_to_string (const void *data,
+ size_t size,
+ char *out,
+ size_t out_size)
{
/**
* 32 characters for encoding
@@ -861,8 +864,6 @@
unsigned int vbit;
const unsigned char *udata;
- GNUNET_assert (data != NULL);
- GNUNET_assert (out != NULL);
udata = data;
if (out_size < (size * 8 + 4) / 5)
{
@@ -902,6 +903,39 @@
/**
+ * Return the base32crockford encoding of the given buffer.
+ *
+ * The returned string will be freshly allocated, and must be free'd
+ * with GNUNET_free().
+ *
+ * @param buffer with data
+ * @param size size of the buffer
+ * @return freshly allocated, null-terminated string
+ */
+char *
+GNUNET_STRINGS_data_to_string_alloc (const void *buf,
+ size_t size)
+{
+ char *str_buf;
+ size_t len = size * 8;
+ char *end;
+
+ if (len % 5 > 0)
+ len += 5 - len % 5;
+ len /= 5;
+ str_buf = GNUNET_malloc (len + 1);
+ end = GNUNET_STRINGS_data_to_string (buf, size, str_buf, len);
+ if (NULL == end)
+ {
+ GNUNET_free (str_buf);
+ return NULL;
+ }
+ *end = '\0';
+ return str_buf;
+}
+
+
+/**
* Convert Crockford Base32hex encoding back to data.
* @a out_size must match exactly the size of the data before it was encoded.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r35045 - in gnunet/src: include util,
gnunet <=