[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 03/14: digestauth: added small helper function to simpli
From: |
gnunet |
Subject: |
[libmicrohttpd] 03/14: digestauth: added small helper function to simplify the code |
Date: |
Thu, 21 Jul 2022 14:08:01 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 348da88b86e038efb483eef32f86a3e5c92ac9d7
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Tue Jul 19 18:07:24 2022 +0300
digestauth: added small helper function to simplify the code
---
src/microhttpd/digestauth.c | 52 +++++++++++++++++++++++----------------------
1 file changed, 27 insertions(+), 25 deletions(-)
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 71561332..6d223e4a 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -388,6 +388,19 @@ digest_update_str (struct DigestAlgorithm *da,
}
+/**
+ * Feed digest calculation with single colon ':' character.
+ * @param da the digest calculation
+ * @param str the zero-terminated string to process
+ */
+_MHD_static_inline void
+digest_update_with_colon (struct DigestAlgorithm *da)
+{
+ static const uint8_t colon = (uint8_t) ':';
+ digest_update (da, &colon, 1);
+}
+
+
/**
* Finally calculate hash (the digest).
* @param da the digest calculation
@@ -1295,22 +1308,14 @@ calculate_nonce (uint64_t nonce_time,
digest_update (da,
timestamp,
sizeof (timestamp));
- digest_update (da,
- (const unsigned char *) ":",
- 1);
- digest_update (da,
- (const unsigned char *) method,
- strlen (method));
- digest_update (da,
- (const unsigned char *) ":",
- 1);
+ digest_update_with_colon (da);
+ digest_update_str (da, method);
+ digest_update_with_colon (da);
if (rnd_size > 0)
digest_update (da,
(const unsigned char *) rnd,
rnd_size);
- digest_update (da,
- (const unsigned char *) ":",
- 1);
+ digest_update_with_colon (da);
digest_update (da,
(const unsigned char *) uri,
uri_len);
@@ -1325,9 +1330,7 @@ calculate_nonce (uint64_t nonce_time,
if (0 != h->value_size)
digest_update (da, (const uint8_t *) h->value, h->value_size);
}
- digest_update (da,
- (const unsigned char *) ":",
- 1);
+ digest_update_with_colon (da);
digest_update (da,
(const unsigned char *) realm,
realm_len);
@@ -1933,7 +1936,6 @@ digest_auth_check_all_inner (struct MHD_Connection
*connection,
char **pbuf)
{
struct MHD_Daemon *daemon = MHD_get_master (connection->daemon);
- static const uint8_t colon = (uint8_t) ':';
const unsigned int digest_size = digest_get_size (da);
char hdigest1[VLA_ARRAY_LEN_DIGEST (digest_size) * 2 + 1];
char hdigest2[VLA_ARRAY_LEN_DIGEST (digest_size) * 2 + 1];
@@ -2136,11 +2138,11 @@ digest_auth_check_all_inner (struct MHD_Connection
*connection,
/* Get 'uri' */
digest_init (da);
digest_update_str (da, connection->method);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
#if 0
/* TODO: add support for "auth-int" */
digest_update_str (da, hentity);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
#endif
unq_res = get_unquoted_param_copy (¶ms->uri, tmp1, ptmp2, &tmp2_size,
&unq_copy);
@@ -2162,9 +2164,9 @@ digest_auth_check_all_inner (struct MHD_Connection
*connection,
{
digest_init (da);
digest_update (da, (const uint8_t *) username, username_len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
digest_update (da, (const uint8_t *) realm, realm_len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
digest_update_str (da, password);
digest_calc_hash (da);
MHD_bin_to_hex (digest_get_bin (da), digest_size, ha1);
@@ -2186,31 +2188,31 @@ digest_auth_check_all_inner (struct MHD_Connection
*connection,
return MHD_DAUTH_ERROR;
if (digest_size != MHD_hex_to_bin (unquoted.str, unquoted.len, response_bin))
return MHD_DAUTH_RESPONSE_WRONG;
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
unq_res = get_unquoted_param (¶ms->nonce, tmp1, ptmp2, &tmp2_size,
&unquoted);
if (_MHD_UNQ_OK != unq_res)
return MHD_DAUTH_ERROR;
digest_update (da, (const uint8_t *) unquoted.str, unquoted.len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
unq_res = get_unquoted_param (¶ms->nc, tmp1, ptmp2, &tmp2_size,
&unquoted);
if (_MHD_UNQ_OK != unq_res)
return MHD_DAUTH_ERROR;
digest_update (da, (const uint8_t *) unquoted.str, unquoted.len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
unq_res = get_unquoted_param (¶ms->cnonce, tmp1, ptmp2, &tmp2_size,
&unquoted);
if (_MHD_UNQ_OK != unq_res)
return MHD_DAUTH_ERROR;
digest_update (da, (const uint8_t *) unquoted.str, unquoted.len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
unq_res = get_unquoted_param (¶ms->qop, tmp1, ptmp2, &tmp2_size,
&unquoted);
if (_MHD_UNQ_OK != unq_res)
return MHD_DAUTH_ERROR;
digest_update (da, (const uint8_t *) unquoted.str, unquoted.len);
- digest_update (da, &colon, 1);
+ digest_update_with_colon (da);
digest_update (da, (const uint8_t *) ha2, digest_size * 2);
ha2 = NULL;
digest_calc_hash (da);
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (bd88a19e -> 22796735), gnunet, 2022/07/21
- [libmicrohttpd] 01/14: test_basicauth: Fixed doxy, gnunet, 2022/07/21
- [libmicrohttpd] 02/14: test_digest: improved test URI, gnunet, 2022/07/21
- [libmicrohttpd] 04/14: digestauth: simplified internal function call, gnunet, 2022/07/21
- [libmicrohttpd] 03/14: digestauth: added small helper function to simplify the code,
gnunet <=
- [libmicrohttpd] 06/14: digest_auth_check(): removed one more large local variable, gnunet, 2022/07/21
- [libmicrohttpd] 07/14: digest calculations: further simplified code, removed some local variables, gnunet, 2022/07/21
- [libmicrohttpd] 08/14: digestauth: removed usage of variable-length arrays, gnunet, 2022/07/21
- [libmicrohttpd] 11/14: digestauth: fixed username extraction with the new API, gnunet, 2022/07/21
- [libmicrohttpd] 10/14: digest_auth_check(): updated the order of parameters check, gnunet, 2022/07/21
- [libmicrohttpd] 12/14: digestauth: do not allocate extra space for extended notation, gnunet, 2022/07/21
- [libmicrohttpd] 05/14: digestauth: added sanity check for digest macros, gnunet, 2022/07/21
- [libmicrohttpd] 09/14: digest_auth_check(): added support for username in extended notation, gnunet, 2022/07/21
- [libmicrohttpd] 13/14: digestauth: added support for extended notation for old API, gnunet, 2022/07/21
- [libmicrohttpd] 14/14: Added test for Digest Auth with username in extended notation, gnunet, 2022/07/21