gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 32/36: Added macro for base64 decoded size


From: gnunet
Subject: [libmicrohttpd] 32/36: Added macro for base64 decoded size
Date: Thu, 01 Jun 2023 12:30:37 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit fbd7cef55e809f9fc75206d3b358a8cd077222c0
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Thu May 25 20:06:12 2023 +0300

    Added macro for base64 decoded size
---
 src/microhttpd/basicauth.c |  2 +-
 src/microhttpd/mhd_str.h   | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/microhttpd/basicauth.c b/src/microhttpd/basicauth.c
index 07b124f1..78818a95 100644
--- a/src/microhttpd/basicauth.c
+++ b/src/microhttpd/basicauth.c
@@ -60,7 +60,7 @@ MHD_basic_auth_get_username_password3 (struct MHD_Connection 
*connection)
   if ((NULL == params->token68.str) || (0 == params->token68.len))
     return NULL;
 
-  decoded_max_len = (params->token68.len / 4) * 3;
+  decoded_max_len = MHD_base64_max_dec_size_ (params->token68.len);
   ret = (struct MHD_BasicAuthInfo *) malloc (sizeof(struct MHD_BasicAuthInfo)
                                              + decoded_max_len + 1);
   if (NULL != ret)
diff --git a/src/microhttpd/mhd_str.h b/src/microhttpd/mhd_str.h
index e2964406..f7a4f79f 100644
--- a/src/microhttpd/mhd_str.h
+++ b/src/microhttpd/mhd_str.h
@@ -739,6 +739,16 @@ MHD_str_quote (const char *unquoted,
 
 #ifdef BAUTH_SUPPORT
 
+/**
+ * Returns the maximum possible size of the Base64 decoded data.
+ * The real recoded size could be up to two bytes smaller.
+ * @param enc_size the size of encoded data, in characters
+ * @return the maximum possible size of the decoded data, in bytes, if
+ *         @a enc_size is valid (properly padded),
+ *         undefined value smaller then @a enc_size if @a enc_size is not valid
+ */
+#define MHD_base64_max_dec_size_(enc_size) (((enc_size) / 4) * 3)
+
 /**
  * Convert Base64 encoded string to binary data.
  * @param base64 the input string with Base64 encoded data, could be NOT zero

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