[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.
- [libmicrohttpd] 08/20: digestauth: added log messages if realm is rejected due to its size, (continued)
- [libmicrohttpd] 08/20: digestauth: added log messages if realm is rejected due to its size, gnunet, 2022/08/15
- [libmicrohttpd] 03/20: daemon.c: cosmetics, gnunet, 2022/08/15
- [libmicrohttpd] 07/20: digestauth: do not use "algorithm" in response header in RFC2069 mode, gnunet, 2022/08/15
- [libmicrohttpd] 11/20: Added MHD_OPTION_DIGEST_AUTH_NONCE_BIND_TYPE to control how to generate and check nonces for Digest Auth, gnunet, 2022/08/15
- [libmicrohttpd] 10/20: daemon.c: fixed and simplified sockaddr alignment handling, gnunet, 2022/08/15
- [libmicrohttpd] 02/20: microhttpd: minor doxy improvement, gnunet, 2022/08/15
- [libmicrohttpd] 17/20: digestauth: minor comment correction, gnunet, 2022/08/15
- [libmicrohttpd] 15/20: test_digestauth2: added third request with new connection, gnunet, 2022/08/15
- [libmicrohttpd] 19/20: digestauth: updated the method of nonce generation in default mode, gnunet, 2022/08/15
- [libmicrohttpd] 20/20: calculate_nonce(): added comments, minor code corrections, gnunet, 2022/08/15
- [libmicrohttpd] 09/20: mhd_str: added function for bin to hex without zero-termination,
gnunet <=
- [libmicrohttpd] 14/20: test_digestauth2: reuse the same connection for the second request, gnunet, 2022/08/15
- [libmicrohttpd] 13/20: test_digestauth2: added testing of nonce bind options, gnunet, 2022/08/15