1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/shell: add sha256sum command

This commit is contained in:
Benjamin Valentin 2022-04-30 18:17:28 +02:00
parent a250c2b5ad
commit ff27db9bce
4 changed files with 36 additions and 1 deletions

View File

@ -198,6 +198,7 @@ PSEUDOMODULES += senml_cbor
PSEUDOMODULES += senml_phydat
PSEUDOMODULES += senml_saul
PSEUDOMODULES += sha1sum
PSEUDOMODULES += sha256sum
PSEUDOMODULES += shell_hooks
PSEUDOMODULES += slipdev_stdio
PSEUDOMODULES += slipdev_l2addr

View File

@ -334,7 +334,7 @@ ifneq (,$(filter shell_commands,$(USEMODULE)))
endif
endif
ifneq (,$(filter md5sum,$(USEMODULE)))
ifneq (,$(filter md5sum sha1sum sha256sum,$(USEMODULE)))
USEMODULE += vfs_util
USEMODULE += hashes
endif

View File

@ -699,4 +699,31 @@ int _vfs_sha1sum_cmd(int argc, char **argv)
return 0;
}
#endif
#if MODULE_SHA256SUM
#include "hashes/sha256.h"
int _vfs_sha256sum_cmd(int argc, char **argv)
{
int res;
uint8_t digest[SHA256_DIGEST_LENGTH];
if (argc < 2) {
printf("usage: %s [file] …\n", argv[0]);
return -1;
}
for (int i = 1; i < argc; ++i) {
const char *file = argv[i];
res = vfs_file_sha256(file, digest,
_shell_vfs_data_buffer, sizeof(_shell_vfs_data_buffer));
if (res < 0) {
printf("%s: error %d\n", file, res);
} else {
_print_digest(digest, sizeof(digest), file);
}
}
return 0;
}
#endif
#endif

View File

@ -223,6 +223,10 @@ extern int _vfs_md5sum_cmd(int argc, char **argv);
extern int _vfs_sha1sum_cmd(int argc, char **argv);
#endif
#ifdef MODULE_SHA256SUM
extern int _vfs_sha256sum_cmd(int argc, char **argv);
#endif
const shell_command_t _shell_command_list[] = {
{"reboot", "Reboot the node", _reboot_handler},
{"version", "Prints current RIOT_VERSION", _version_handler},
@ -282,6 +286,9 @@ const shell_command_t _shell_command_list[] = {
#ifdef MODULE_SHA1SUM
{"sha1sum", "Compute and check SHA1 message digest", _vfs_sha1sum_cmd},
#endif
#ifdef MODULE_SHA256SUM
{"sha256sum", "Compute and check SHA256 message digest", _vfs_sha256sum_cmd},
#endif
#ifdef MODULE_GNRC_IPV6_NIB
{"nib", "Configure neighbor information base", _gnrc_ipv6_nib},
#endif