gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] 09/20: mhd_str: added function for bin to hex without ze


From: gnunet
Subject: [libmicrohttpd] 09/20: mhd_str: added function for bin to hex without zero-termination
Date: Mon, 15 Aug 2022 20:38:35 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit b115e254b32f58dea98a0f30ad1510c3223b8a1b
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Sat Aug 13 11:44:50 2022 +0300

    mhd_str: added function for bin to hex without zero-termination
---
 src/microhttpd/digestauth.c       |  1 -
 src/microhttpd/mhd_str.c          | 15 ++++++++++++++-
 src/microhttpd/mhd_str.h          | 21 ++++++++++++++++++---
 src/microhttpd/test_str_base64.c  |  6 +++---
 src/microhttpd/test_str_bin_hex.c |  2 +-
 5 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 7d0719ba..4b4eac7c 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -1603,7 +1603,6 @@ calculate_add_nonce_with_retry (struct MHD_Connection 
*const connection,
       return false;
     }
     memcpy (nonce, nonce2, NONCE_STD_LEN (digest_size));
-    mhd_assert (0 == nonce[NONCE_STD_LEN (digest_size)]);
   }
   return true;
 }
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index cf2e43c3..6099f93c 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1382,11 +1382,24 @@ MHD_bin_to_hex (const void *bin,
     j = b & 0x0f;
     hex[i * 2 + 1] = (char) ((j < 10) ? (j + '0') : (j - 10 + 'a'));
   }
-  hex[i * 2] = 0;
   return i * 2;
 }
 
 
+size_t
+MHD_bin_to_hex_z (const void *bin,
+                  size_t size,
+                  char *hex)
+{
+  size_t res;
+
+  res = MHD_bin_to_hex (bin, size, hex);
+  hex[res] = 0;
+
+  return res;
+}
+
+
 size_t
 MHD_hex_to_bin (const char *hex,
                 size_t len,
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index dd74e602..284ad853 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -497,6 +497,21 @@ MHD_uint8_to_str_pad (uint8_t val,
                       char *buf,
                       size_t buf_size);
 
+
+/**
+ * Convert @a size bytes from input binary data to lower case
+ * hexadecimal digits.
+ * Result is NOT zero-terminated
+ * @param bin the pointer to the binary data to convert
+ * @param size the size in bytes of the binary data to convert
+ * @param[out] hex the output buffer, should be at least 2 * @a size
+ * @return The number of characters written to the output buffer.
+ */
+size_t
+MHD_bin_to_hex (const void *bin,
+                size_t size,
+                char *hex);
+
 /**
  * Convert @a size bytes from input binary data to lower case
  * hexadecimal digits, zero-terminate the result.
@@ -507,9 +522,9 @@ MHD_uint8_to_str_pad (uint8_t val,
  *         not including terminating zero.
  */
 size_t
-MHD_bin_to_hex (const void *bin,
-                size_t size,
-                char *hex);
+MHD_bin_to_hex_z (const void *bin,
+                  size_t size,
+                  char *hex);
 
 /**
  * Convert hexadecimal digits to binary data.
diff --git a/src/microhttpd/test_str_base64.c b/src/microhttpd/test_str_base64.c
index 9daa6cb7..1821d116 100644
--- a/src/microhttpd/test_str_base64.c
+++ b/src/microhttpd/test_str_base64.c
@@ -86,7 +86,7 @@ expect_decoded_n (const char *const encoded, const size_t 
encoded_len,
     }
     else
     {
-      prnt_size = MHD_bin_to_hex (buf, res_size, prnt);
+      prnt_size = MHD_bin_to_hex_z (buf, res_size, prnt);
       mhd_assert (2 * res_size == prnt_size);
 
       fprintf (stderr,
@@ -96,7 +96,7 @@ expect_decoded_n (const char *const encoded, const size_t 
encoded_len,
                (int) prnt_size, prnt, (unsigned) decoded_size,
                (unsigned) res_size);
     }
-    prnt_size = MHD_bin_to_hex (decoded, decoded_size, prnt);
+    prnt_size = MHD_bin_to_hex_z (decoded, decoded_size, prnt);
     mhd_assert (2 * decoded_size == prnt_size);
     fprintf (stderr,
              "\tEXPECTED: MHD_base64_to_bin_n ('%.*s', %u, ->%.*sh, %u)"
@@ -620,7 +620,7 @@ expect_fail_n (const char *const encoded, const size_t 
encoded_len,
     }
     else
     {
-      prnt_size = MHD_bin_to_hex (buf, res_size, prnt);
+      prnt_size = MHD_bin_to_hex_z (buf, res_size, prnt);
       mhd_assert (2 * res_size == prnt_size);
 
       fprintf (stderr,
diff --git a/src/microhttpd/test_str_bin_hex.c 
b/src/microhttpd/test_str_bin_hex.c
index 2b45040a..557146eb 100644
--- a/src/microhttpd/test_str_bin_hex.c
+++ b/src/microhttpd/test_str_bin_hex.c
@@ -168,7 +168,7 @@ expect_decoded_n (const char *const hex, const size_t 
hex_len,
     unsigned int check_res = 0;
 
     memset (buf, fill_chr, sizeof(buf)); /* Fill buffer with some character */
-    res_size = MHD_bin_to_hex (bin, bin_size, buf);
+    res_size = MHD_bin_to_hex_z (bin, bin_size, buf);
 
     if (res_size != hex_len)
     {

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]