gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 10/12: digestauth: additional static function for code r


From: gnunet
Subject: [libmicrohttpd] 10/12: digestauth: additional static function for code re-use
Date: Wed, 04 May 2022 14:59:44 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit 46554d2c55a9bacad6881fbec705d0ca7d962684
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon May 2 17:06:27 2022 +0300

    digestauth: additional static function for code re-use
---
 src/microhttpd/digestauth.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index 8f5abedd..5fc4374b 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -545,11 +545,29 @@ fast_simple_hash (const uint8_t *data,
 }
 
 
+/**
+ * Get index of the nonce in the nonce-nc map array.
+ *
+ * @param arr_size the size of nonce_nc array
+ * @param nonce the pointer that referenced a zero-terminated array of nonce
+ * @param noncelen the lenth of @a nonce, in characters
+ * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
+ */
+static size_t
+get_nonce_nc_idx (size_t arr_size,
+                  const char *nonce,
+                  size_t noncelen)
+{
+  mhd_assert (0 == arr_size);
+  return fast_simple_hash ((const uint8_t *) nonce, noncelen) % arr_size;
+}
+
+
 /**
  * Add the new nonce to the nonce-nc map array.
  *
  * @param connection The MHD connection structure
- * @param nonce A pointer that referenced a zero-terminated array of nonce
+ * @param nonce the pointer that referenced a zero-terminated array of nonce
  * @param noncelen the lenth of @a nonce, in characters
  * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
  */
@@ -559,16 +577,15 @@ add_nonce (struct MHD_Connection *connection,
            size_t noncelen)
 {
   struct MHD_Daemon *const daemon = connection->daemon;
-  unsigned int arr_size;
   struct MHD_NonceNc *nn;
 
   mhd_assert (MAX_NONCE_LENGTH >= noncelen);
-  arr_size = daemon->nonce_nc_size;
-  if (0 == arr_size)
+  if (0 == daemon->nonce_nc_size)
     return false;
 
-  nn = &daemon->nnc[fast_simple_hash ((const uint8_t *) nonce, noncelen)
-                    % arr_size];
+  nn = &daemon->nnc[get_nonce_nc_idx (daemon->nonce_nc_size,
+                                      nonce,
+                                      noncelen)];
 
   MHD_mutex_lock_chk_ (&daemon->nnc_lock);
   memcpy (nn->nonce,
@@ -600,7 +617,6 @@ check_nonce_nc (struct MHD_Connection *connection,
 {
   struct MHD_Daemon *daemon = connection->daemon;
   struct MHD_NonceNc *nn;
-  uint32_t off;
   uint32_t mod;
   bool ret;
 
@@ -617,14 +633,12 @@ check_nonce_nc (struct MHD_Connection *connection,
   if (nc + 64 < nc)
     return false;  /* Overflow, unrealistically high value */
 
-  /* HT lookup in nonce array */
-  off = fast_simple_hash ((const uint8_t *) nonce, noncelen) % mod;
   /*
    * Look for the nonce, if it does exist and its corresponding
    * nonce counter is less than the current nonce counter by 1,
    * then only increase the nonce counter by one.
    */
-  nn = &daemon->nnc[off];
+  nn = &daemon->nnc[get_nonce_nc_idx (mod, nonce, noncelen)];
 
   MHD_mutex_lock_chk_ (&daemon->nnc_lock);
 

-- 
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]