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

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


The following commit(s) were added to refs/heads/master by this push:
     new c3e628c45 nshlib/md5: Support reading from standard input
c3e628c45 is described below

commit c3e628c45a8e4b4984c11d8e222bc4bc4d035d5e
Author: wangjianyu3 <wangjian...@xiaomi.com>
AuthorDate: Wed Jul 2 11:40:03 2025 +0800

    nshlib/md5: Support reading from standard input
    
    Sometimes users may want to calculate the MD5 of part of a file(e.g. check
    partition contents for debug after flashing, size of which may be greater
    than image). This can be done with the "dd" command and pipes, the "md5"
    command just needs to support reading from standard input. For example:
    `dd if=/dev/virtblk0 bs=512 count=1 | md5`.
    
    Signed-off-by: wangjianyu3 <wangjian...@xiaomi.com>
---
 nshlib/nsh_codeccmd.c | 20 ++++++++++++++++++++
 nshlib/nsh_command.c  |  3 ++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index 796bcffd9..91b3953ff 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -509,6 +509,26 @@ int cmd_md5(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
           return ret;
         }
     }
+  else if (argc == 1)
+    {
+      MD5_CTX ctx;
+
+      md5_init(&ctx);
+
+      while (1)
+        {
+          ret = nsh_read(vtbl, digest, sizeof(digest));
+          if (ret <= 0)
+            {
+              ret = ret < 0 ? -errno : 0;
+              break;
+            }
+
+          md5_update(&ctx, digest, ret);
+        }
+
+      md5_final(digest, &ctx);
+    }
   else
     {
       md5_sum((FAR unsigned char *)argv[1], strlen(argv[1]), digest);
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index dc8fab481..7bbaf69be 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -353,7 +353,8 @@ static const struct cmdmap_s g_cmdmap[] =
 
 #if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
 #  ifndef CONFIG_NSH_DISABLE_MD5
-  CMD_MAP("md5",      cmd_md5,      2, 3, "[-f] <string or filepath>"),
+  CMD_MAP("md5",      cmd_md5,      1, 3,
+          "[string] or [-f <filepath>] or read stdin"),
 #  endif
 #endif
 

Reply via email to