[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 04/15: mhd_str: added MHD_hex_to_bin() internal function
From: |
gnunet |
Subject: |
[libmicrohttpd] 04/15: mhd_str: added MHD_hex_to_bin() internal function |
Date: |
Tue, 19 Jul 2022 16:51:12 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit ee06f77543fa335befa8159b9ffdafc35d30fb33
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Wed Jun 22 16:31:39 2022 +0300
mhd_str: added MHD_hex_to_bin() internal function
---
src/microhttpd/mhd_str.c | 36 ++++++++++++++++++++++++++++++++++++
src/microhttpd/mhd_str.h | 18 ++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/src/microhttpd/mhd_str.c b/src/microhttpd/mhd_str.c
index ef870e61..cf2e43c3 100644
--- a/src/microhttpd/mhd_str.c
+++ b/src/microhttpd/mhd_str.c
@@ -1387,6 +1387,42 @@ MHD_bin_to_hex (const void *bin,
}
+size_t
+MHD_hex_to_bin (const char *hex,
+ size_t len,
+ void *bin)
+{
+ uint8_t *const out = (uint8_t *) bin;
+ size_t r;
+ size_t w;
+
+ if (0 == len)
+ return 0;
+ r = 0;
+ w = 0;
+ if (0 != len % 2)
+ {
+ /* Assume the first byte is encoded with single digit */
+ const int l = toxdigitvalue (hex[r++]);
+ if (0 > l)
+ return 0;
+ out[w++] = (uint8_t) ((unsigned int) l);
+ }
+ while (r < len)
+ {
+ const int h = toxdigitvalue (hex[r++]);
+ const int l = toxdigitvalue (hex[r++]);
+ if ((0 > h) || (0 > l))
+ return 0;
+ out[w++] = ( (((uint8_t) ((unsigned int) h)) << 4)
+ | ((uint8_t) ((unsigned int) l)) );
+ }
+ mhd_assert (len == r);
+ mhd_assert ((len + 1) / 2 == w);
+ return w;
+}
+
+
size_t
MHD_str_pct_decode_strict_n_ (const char *pct_encoded,
size_t pct_encoded_len,
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index ec8b5cf4..91219cba 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -493,6 +493,24 @@ MHD_bin_to_hex (const void *bin,
size_t size,
char *hex);
+/**
+ * Convert hexadecimal digits to binary data.
+ *
+ * The input decoded byte-by-byte (each byte is two hexadecimal digits).
+ * If length is an odd number, extra leading zero is assumed.
+ *
+ * @param hex the input string with hexadecimal digits
+ * @param len the length of the input string
+ * @param[out] bin the output buffer, must be at least len/2 bytes long (or
+ * len/2 + 1 if @a len is not even number)
+ * @return the number of bytes written to the output buffer,
+ * zero if found any character which is not hexadecimal digits
+ */
+size_t
+MHD_hex_to_bin (const char *hex,
+ size_t len,
+ void *bin);
+
/**
* Decode string with percent-encoded characters as defined by
* RFC 3986 #section-2.1.
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (d629ada1 -> 76b5b195), gnunet, 2022/07/19
- [libmicrohttpd] 03/15: Use new functions for decode request URLs, gnunet, 2022/07/19
- [libmicrohttpd] 01/15: mhd_str: added functions for percent-decoding, gnunet, 2022/07/19
- [libmicrohttpd] 02/15: Added tests for percent-decoding functions, gnunet, 2022/07/19
- [libmicrohttpd] 05/15: Added tests for hex <-> binary functions, gnunet, 2022/07/19
- [libmicrohttpd] 12/15: microhttpd.h: added special enum for hash types, gnunet, 2022/07/19
- [libmicrohttpd] 04/15: mhd_str: added MHD_hex_to_bin() internal function,
gnunet <=
- [libmicrohttpd] 09/15: Digest: check whether all required parameters are present before doing heavy calculations, gnunet, 2022/07/19
- [libmicrohttpd] 06/15: mhd_str: added macros for simple comparison against static strings, gnunet, 2022/07/19
- [libmicrohttpd] 08/15: Digest: use binary zero to separate get params in digest, gnunet, 2022/07/19
- [libmicrohttpd] 07/15: Added new functions MHD_digest_auth_get_request_info3() and MHD_digest_auth_get_username3(), gnunet, 2022/07/19
- [libmicrohttpd] 15/15: microhttpd.h: formatted some deprecation warnings, gnunet, 2022/07/19
- [libmicrohttpd] 10/15: Digest: moved URI match check to separate function, avoid one memcpy(), gnunet, 2022/07/19
- [libmicrohttpd] 11/15: digest_auth_check: mostly rewritten, simplified, optimised, gnunet, 2022/07/19
- [libmicrohttpd] 13/15: digest: small internal refactoring to clarify used hash type, gnunet, 2022/07/19
- [libmicrohttpd] 14/15: digest_auth_check(): check and report wrong algorithm, gnunet, 2022/07/19