Skip to content

Commit

Permalink
sys/shell: add sha256sum command
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed May 17, 2022
1 parent a250c2b commit cc73e3f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions sys/shell/commands/sc_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions sys/shell/commands/shell_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cc73e3f

Please sign in to comment.