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

sys/shell: add md5sum command

This commit is contained in:
Benjamin Valentin 2022-04-30 18:03:04 +02:00
parent 427d06c987
commit 845450c663
4 changed files with 51 additions and 0 deletions

View File

@ -139,6 +139,7 @@ PSEUDOMODULES += mpu_stack_guard
## This is a protection mechanism which makes exploitation of buffer overflows significantly harder.
PSEUDOMODULES += mpu_noexec_ram
PSEUDOMODULES += md5sum
PSEUDOMODULES += mtd_write_page
PSEUDOMODULES += nanocoap_%
PSEUDOMODULES += netdev_default

View File

@ -334,6 +334,11 @@ ifneq (,$(filter shell_commands,$(USEMODULE)))
endif
endif
ifneq (,$(filter md5sum,$(USEMODULE)))
USEMODULE += vfs_util
USEMODULE += hashes
endif
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
USEMODULE += sema_deprecated
USEMODULE += ztimer64_usec

View File

@ -30,6 +30,9 @@
#include <fcntl.h>
#include "vfs.h"
#if MODULE_VFS_UTIL
#include "vfs_util.h"
#endif
#define SHELL_VFS_BUFSIZE 256
static uint8_t _shell_vfs_data_buffer[SHELL_VFS_BUFSIZE];
@ -634,4 +637,39 @@ int _vfs_handler(int argc, char **argv)
return 1;
}
}
static inline void _print_digest(const uint8_t *digest, size_t len, const char *file)
{
for (unsigned i = 0; i < len; ++i) {
printf("%02x", digest[i]);
}
printf(" %s\n", file);
}
#if MODULE_MD5SUM
#include "hashes/md5.h"
int _vfs_md5sum_cmd(int argc, char **argv)
{
int res;
uint8_t digest[MD5_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_md5(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

@ -215,6 +215,10 @@ extern int _bootloader_handler(int argc, char **argv);
extern int _gnrc_udp_cmd(int argc, char **argv);
#endif
#ifdef MODULE_MD5SUM
extern int _vfs_md5sum_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},
@ -268,6 +272,9 @@ const shell_command_t _shell_command_list[] = {
#ifdef MODULE_RTT_CMD
{"rtt", "control RTC peripheral interface", _rtt_handler},
#endif
#ifdef MODULE_MD5SUM
{"md5sum", "Compute and check MD5 message digest", _vfs_md5sum_cmd},
#endif
#ifdef MODULE_GNRC_IPV6_NIB
{"nib", "Configure neighbor information base", _gnrc_ipv6_nib},
#endif