You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/21 02:48:33 UTC

[nuttx-apps] branch master updated (a4ab405fa -> a46a661b3)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


    from a4ab405fa Fix typo in uint8_t
     new 2459476b6 nshlib: Implementation of modifying command md5
     new a46a661b3 Update nshlib/nsh_codeccmd.c

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 nshlib/nsh_codeccmd.c | 109 +++++++++++++-------------------------------------
 1 file changed, 27 insertions(+), 82 deletions(-)


[nuttx-apps] 02/02: Update nshlib/nsh_codeccmd.c

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit a46a661b341b619ec96493df0804b8060fe42c0c
Author: 0528Mike <10...@users.noreply.github.com>
AuthorDate: Thu Sep 21 00:38:18 2023 +0800

    Update nshlib/nsh_codeccmd.c
    
    Co-authored-by: Petro Karashchenko <pe...@gmail.com>
---
 nshlib/nsh_codeccmd.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index 65358c158..859405d5c 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -509,7 +509,7 @@ int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
     }
   else
     {
-      md5_sum((unsigned char *)argv[1], strlen(argv[1]), digest);
+      md5_sum((FAR unsigned char *)argv[1], strlen(argv[1]), digest);
     }
 
   for (i = 0; i < 16; i++)


[nuttx-apps] 01/02: nshlib: Implementation of modifying command md5

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 2459476b6572c849ef7f504b167f184863cf1729
Author: wangmingrong <wa...@xiaomi.com>
AuthorDate: Wed Aug 30 19:36:20 2023 +0800

    nshlib: Implementation of modifying command md5
    
    Simplify the "cmd_codecs_proc" md5 related framework and modify the implementation of the command md5:
    
    Signed-off-by: wangmingrong <wa...@xiaomi.com>
---
 nshlib/nsh_codeccmd.c | 109 +++++++++++++-------------------------------------
 1 file changed, 27 insertions(+), 82 deletions(-)

diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index 9b3efdcce..65358c158 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -96,8 +96,7 @@
 #endif
 
 #if defined(HAVE_CODECS_URLENCODE) || defined(HAVE_CODECS_URLDECODE) || \
-    defined(HAVE_CODECS_BASE64ENC) || defined(HAVE_CODECS_BASE64DEC) || \
-    defined(HAVE_CODECS_HASH_MD5)
+    defined(HAVE_CODECS_BASE64ENC) || defined(HAVE_CODECS_BASE64DEC)
 #  define NEED_CMD_CODECS_PROC 1
 #endif
 
@@ -184,18 +183,6 @@ static void b64dec_cb(FAR char *src, int srclen, FAR char *dest,
 }
 #endif
 
-/****************************************************************************
- * Name: md5_cb
- ****************************************************************************/
-
-#ifdef HAVE_CODECS_HASH_MD5
-static void md5_cb(FAR char *src, int srclen, FAR char *dest,
-                   FAR int *destlen, int mode)
-{
-  md5_update((MD5_CTX *)dest, (unsigned char *)src, srclen);
-}
-#endif
-
 /****************************************************************************
  * Name: calc_codec_buffsize
  ****************************************************************************/
@@ -235,14 +222,6 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc,
                            FAR char **argv, uint8_t mode,
                            codec_callback_t func)
 {
-#ifdef HAVE_CODECS_HASH_MD5
-  static const unsigned char hexchars[] = "0123456789abcdef";
-  MD5_CTX ctx;
-  unsigned char mac[16];
-  FAR unsigned char *src;
-  FAR char *dest;
-#endif
-
   FAR char *localfile = NULL;
   FAR char *srcbuf = NULL;
   FAR char *destbuf = NULL;
@@ -318,13 +297,6 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc,
       goto errout;
     }
 
-#ifdef HAVE_CODECS_HASH_MD5
-  if (mode == CODEC_MODE_HASH_MD5)
-    {
-      md5_init(&ctx);
-    }
-#endif
-
   if (isfile)
     {
       /* Get the local file name */
@@ -403,41 +375,13 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc,
           memset(destbuf, 0, buflen);
           if (func)
             {
-#ifdef HAVE_CODECS_HASH_MD5
-              if (mode == CODEC_MODE_HASH_MD5)
-                {
-                  func(srcbuf, ret, (char *)&ctx, &buflen, 0);
-                }
-              else
-#endif
-                {
-                  func(srcbuf, ret, destbuf, &buflen, iswebsafe ? 1 : 0);
-                  nsh_output(vtbl, "%s", destbuf);
-                }
+              func(srcbuf, ret, destbuf, &buflen, iswebsafe ? 1 : 0);
+              nsh_output(vtbl, "%s", destbuf);
             }
 
           buflen = calc_codec_buffsize(srclen + 2, mode);
         }
 
-#ifdef HAVE_CODECS_HASH_MD5
-      if (mode == CODEC_MODE_HASH_MD5)
-        {
-          int i;
-
-          md5_final(mac, &ctx);
-          src  = mac;
-          dest = destbuf;
-          for (i = 0; i < 16; i++, src++)
-            {
-              *dest++ = hexchars[(*src) >> 4];
-              *dest++ = hexchars[(*src) & 0x0f];
-            }
-
-          *dest = '\0';
-          nsh_output(vtbl, "%s\n", destbuf);
-        }
-
-#endif
       ret = OK;
       goto exit;
     }
@@ -456,28 +400,7 @@ static int cmd_codecs_proc(FAR struct nsh_vtbl_s *vtbl, int argc,
       memset(destbuf, 0, buflen);
       if (func)
         {
-#ifdef HAVE_CODECS_HASH_MD5
-          if (mode == CODEC_MODE_HASH_MD5)
-            {
-              int i;
-
-              func(srcbuf, srclen, (char *)&ctx, &buflen, 0);
-              md5_final(mac, &ctx);
-              src  = mac;
-              dest = destbuf;
-              for (i = 0; i < 16; i++, src++)
-                {
-                  *dest++ = hexchars[(*src) >> 4];
-                  *dest++ = hexchars[(*src) & 0x0f];
-                }
-
-              *dest = '\0';
-            }
-          else
-#endif
-            {
-              func(srcbuf, srclen, destbuf, &buflen, iswebsafe ? 1 : 0);
-            }
+          func(srcbuf, srclen, destbuf, &buflen, iswebsafe ? 1 : 0);
         }
 
       nsh_output(vtbl, "%s\n", destbuf);
@@ -572,7 +495,29 @@ int cmd_base64decode(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 #ifdef HAVE_CODECS_HASH_MD5
 int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
-  return cmd_codecs_proc(vtbl, argc, argv, CODEC_MODE_HASH_MD5, md5_cb);
+  int i;
+  int ret = OK;
+  unsigned char digest[16];
+
+  if (argc == 3 && !strncmp(argv[1], "-f", 2))
+    {
+      ret = md5_file(argv[2], digest);
+      if (ret < 0)
+        {
+          return ret;
+        }
+    }
+  else
+    {
+      md5_sum((unsigned char *)argv[1], strlen(argv[1]), digest);
+    }
+
+  for (i = 0; i < 16; i++)
+    {
+      nsh_output(vtbl, "%02x", digest[i]);
+    }
+
+  return ret;
 }
 #endif