Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,26 @@ int filesystem_cmd_b64encode(int argc, char *argv[]) {
return 0;
}

int filesystem_cmd_b64decode(int argc, char *argv[]) {
(void) argc;
char *buf = malloc(strlen(argv[1]) * 1.5 + 1);
unsigned int decoded_size = b64_decode((unsigned char *)argv[1], strlen(argv[1]), (unsigned char *)buf);
if (!decoded_size) {
printf("No bytes decoded.\r\n");
return 0;
}
if (!strcmp(argv[2], ">>")) {
if (filesystem_file_exists(argv[3])) {
filesystem_append_file(argv[3], buf, decoded_size);
} else {
printf("b64decode: %s: No such file\r\n", argv[3]);
}
} else if (!strcmp(argv[2], ">")) {
filesystem_write_file(argv[3], buf, decoded_size);
}
return 0;
}

int filesystem_cmd_df(int argc, char *argv[]) {
(void) argc;
(void) argv;
Expand Down
1 change: 1 addition & 0 deletions filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ bool filesystem_append_file(char *filename, char *text, int32_t length);
int filesystem_cmd_ls(int argc, char *argv[]);
int filesystem_cmd_cat(int argc, char *argv[]);
int filesystem_cmd_b64encode(int argc, char *argv[]);
int filesystem_cmd_b64decode(int argc, char *argv[]);
int filesystem_cmd_df(int argc, char *argv[]);
int filesystem_cmd_rm(int argc, char *argv[]);
int filesystem_cmd_format(int argc, char *argv[]);
Expand Down
7 changes: 7 additions & 0 deletions shell/shell_cmd_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ shell_command_t g_shell_commands[] = {
.max_args = 1,
.cb = filesystem_cmd_b64encode,
},
{
.name = "b64decode",
.help = "usage: b64decode <PAYLOAD> {>, >>} <FILE>",
.min_args = 3,
.max_args = 3,
.cb = filesystem_cmd_b64decode,
},
{
.name = "df",
.help = "print filesystem free space",
Expand Down