mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-20 12:55:43 +08:00
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 <wangjianyu3@xiaomi.com>
This commit is contained in:

committed by
Alan C. Assis

parent
ecd7b84871
commit
c3e628c45a
@@ -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);
|
||||
|
Reference in New Issue
Block a user