Skip to content

Commit

Permalink
Implemented #188 (#189)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Aug 10, 2023
1 parent a02382f commit 89fa750
Show file tree
Hide file tree
Showing 51 changed files with 243 additions and 69 deletions.
2 changes: 1 addition & 1 deletion flipperzero-firmware_official_dev
4 changes: 3 additions & 1 deletion totp/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ App(
"wolfcrypt/src/sha256.c",
"wolfcrypt/src/sha512.c"
],
cflags=["-Wno-error", "-include${FAP_SRC_DIR}/wolfssl_config.h"]
cflags=["-Wno-error"],
cdefines=["HAVE_CONFIG_H"],
cincludes=["config/wolfssl"]
),
],
)
2 changes: 2 additions & 0 deletions totp/cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ static TotpIteratorUpdateTokenResult
return TotpIteratorUpdateTokenResultSuccess;
}

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_add_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_ADD ", " TOTP_CLI_COMMAND_ADD_ALT
", " TOTP_CLI_COMMAND_ADD_ALT2 " Add new token\r\n");
Expand Down Expand Up @@ -155,6 +156,7 @@ void totp_cli_command_add_docopt_options() {
TOTP_CLI_PRINTF(" # " TOKEN_AUTOMATION_FEATURE_TYPE_SLOWER_NAME
" - Type slower\r\n");
}
#endif

void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/add/add.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#pragma once

#include <cli/cli.h>
#include "../../../config/app/config.h"
#include "../../../types/plugin_state.h"

#define TOTP_CLI_COMMAND_ADD "add"
#define TOTP_CLI_COMMAND_ADD_ALT "mk"
#define TOTP_CLI_COMMAND_ADD_ALT2 "new"

void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_add_docopt_commands();
void totp_cli_command_add_docopt_usage();
void totp_cli_command_add_docopt_arguments();
void totp_cli_command_add_docopt_options();
void totp_cli_command_add_docopt_options();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/automation/automation.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX "-k"
#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT "layout"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_automation_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_AUTOMATION " Get or set automation settings\r\n");
}
Expand Down Expand Up @@ -45,6 +46,7 @@ void totp_cli_command_automation_docopt_options() {
", " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY
"\r\n");
}
#endif

static void print_method(AutomationMethod method, const char* color) {
#ifdef TOTP_BADBT_AUTOMATION_ENABLED
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/automation/automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_AUTOMATION "automation"

void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_automation_docopt_commands();
void totp_cli_command_automation_docopt_usage();
void totp_cli_command_automation_docopt_arguments();
void totp_cli_command_automation_docopt_options();
void totp_cli_command_automation_docopt_options();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/delete/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define TOTP_CLI_COMMAND_DELETE_ARG_FORCE_PREFIX "-f"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_delete_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_DELETE ", " TOTP_CLI_COMMAND_DELETE_ALT
" Delete existing token\r\n");
Expand All @@ -30,6 +31,7 @@ void totp_cli_command_delete_docopt_options() {
TOTP_CLI_PRINTF(" " DOCOPT_SWITCH(
TOTP_CLI_COMMAND_DELETE_ARG_FORCE_PREFIX) " Force command to do not ask user for interactive confirmation\r\n");
}
#endif

void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/delete/delete.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_DELETE "delete"
#define TOTP_CLI_COMMAND_DELETE_ALT "rm"

void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_delete_docopt_commands();
void totp_cli_command_delete_docopt_usage();
void totp_cli_command_delete_docopt_arguments();
void totp_cli_command_delete_docopt_options();
void totp_cli_command_delete_docopt_options();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/details/details.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static void print_automation_features(const TokenInfo* token_info) {
}
}

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_details_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_DETAILS ", " TOTP_CLI_COMMAND_DETAILS_ALT
" Displays token details\r\n");
Expand All @@ -47,6 +48,7 @@ void totp_cli_command_details_docopt_usage() {
TOTP_CLI_COMMAND_DETAILS
" | " TOTP_CLI_COMMAND_DETAILS_ALT) " " DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ARG_INDEX) "\r\n");
}
#endif

void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
3 changes: 3 additions & 0 deletions totp/cli/commands/details/details.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_DETAILS "lsattr"
#define TOTP_CLI_COMMAND_DETAILS_ALT "cat"

void totp_cli_command_details_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_details_docopt_commands();
void totp_cli_command_details_docopt_usage();
#endif
7 changes: 7 additions & 0 deletions totp/cli/commands/help/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "../automation/automation.h"
#include "../details/details.h"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_help_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_HELP ", " TOTP_CLI_COMMAND_HELP_ALT
", " TOTP_CLI_COMMAND_HELP_ALT2 " Show command usage help\r\n");
Expand All @@ -22,8 +23,10 @@ void totp_cli_command_help_docopt_usage() {
TOTP_CLI_COMMAND_HELP " | " TOTP_CLI_COMMAND_HELP_ALT
" | " TOTP_CLI_COMMAND_HELP_ALT2) "\r\n");
}
#endif

void totp_cli_command_help_handle() {
#ifdef TOTP_CLI_RICH_HELP_ENABLED
TOTP_CLI_PRINTF("Usage:\r\n");
totp_cli_command_help_docopt_usage();
totp_cli_command_list_docopt_usage();
Expand Down Expand Up @@ -66,4 +69,8 @@ void totp_cli_command_help_handle() {
totp_cli_command_delete_docopt_options();
totp_cli_command_pin_docopt_options();
totp_cli_command_automation_docopt_options();
#else
TOTP_CLI_PRINTF(
"All the TOTP CLI commands, their arguments, options and usage can be found here https://t.ly/_6pJG");
#endif
}
5 changes: 4 additions & 1 deletion totp/cli/commands/help/help.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#pragma once

#include "../../../config/app/config.h"
#include <cli/cli.h>

#define TOTP_CLI_COMMAND_HELP "help"
#define TOTP_CLI_COMMAND_HELP_ALT "h"
#define TOTP_CLI_COMMAND_HELP_ALT2 "?"

void totp_cli_command_help_handle();
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_help_docopt_commands();
void totp_cli_command_help_docopt_usage();
void totp_cli_command_help_docopt_usage();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/list/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../../../ui/scene_director.h"
#include "../../cli_helpers.h"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_list_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_LIST ", " TOTP_CLI_COMMAND_LIST_ALT
" List all available tokens\r\n");
Expand All @@ -15,6 +16,7 @@ void totp_cli_command_list_docopt_usage() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " DOCOPT_REQUIRED(
TOTP_CLI_COMMAND_LIST " | " TOTP_CLI_COMMAND_LIST_ALT) "\r\n");
}
#endif

void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
3 changes: 3 additions & 0 deletions totp/cli/commands/list/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_LIST "list"
#define TOTP_CLI_COMMAND_LIST_ALT "ls"

void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_list_docopt_commands();
void totp_cli_command_list_docopt_usage();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/move/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#define TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX "new_index"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_move_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE ", " TOTP_CLI_COMMAND_MOVE_ALT
" Move token\r\n");
Expand All @@ -26,6 +27,7 @@ void totp_cli_command_move_docopt_arguments() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_MOVE_ARG_NEW_INDEX
" New token index in the list\r\n");
}
#endif

void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/move/move.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_MOVE "move"
#define TOTP_CLI_COMMAND_MOVE_ALT "mv"

void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_move_docopt_commands();
void totp_cli_command_move_docopt_usage();
void totp_cli_command_move_docopt_arguments();
void totp_cli_command_move_docopt_arguments();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/notification/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#define TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND "sound"
#define TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "vibro"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_notification_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NOTIFICATION
" Get or set notification method\r\n");
Expand All @@ -27,6 +28,7 @@ void totp_cli_command_notification_docopt_arguments() {
", " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_SOUND
", " TOTP_CLI_COMMAND_NOTIFICATION_METHOD_VIBRO "\r\n");
}
#endif

static void
totp_cli_command_notification_print_method(NotificationMethod method, const char* color) {
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/notification/notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_NOTIFICATION "notify"

void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_notification_docopt_commands();
void totp_cli_command_notification_docopt_usage();
void totp_cli_command_notification_docopt_arguments();
void totp_cli_command_notification_docopt_arguments();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/pin/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX "-c"
#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT "slot"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_pin_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_PIN " Set\\change\\remove PIN\r\n");
}
Expand All @@ -37,6 +38,7 @@ void totp_cli_command_pin_docopt_options() {
ACCEPTABLE_CRYPTO_KEY_SLOT_START,
ACCEPTABLE_CRYPTO_KEY_SLOT_END);
}
#endif

static inline uint8_t totp_cli_key_to_pin_code(uint8_t key) {
uint8_t code = 0;
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/pin/pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_PIN "pin"

void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_pin_docopt_commands();
void totp_cli_command_pin_docopt_usage();
void totp_cli_command_pin_docopt_options();
void totp_cli_command_pin_docopt_options();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/reset/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define TOTP_CLI_RESET_CONFIRMATION_KEYWORD "YES"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_reset_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_RESET
" Reset application to default settings\r\n");
Expand All @@ -16,6 +17,7 @@ void totp_cli_command_reset_docopt_commands() {
void totp_cli_command_reset_docopt_usage() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n");
}
#endif

void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli) {
TOTP_CLI_LOCK_UI(plugin_state);
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/reset/reset.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_RESET "reset"

void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_reset_docopt_commands();
void totp_cli_command_reset_docopt_usage();
void totp_cli_command_reset_docopt_usage();
#endif
2 changes: 2 additions & 0 deletions totp/cli/commands/timezone/timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#define TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE "timezone"

#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_timezone_docopt_commands() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE ", " TOTP_CLI_COMMAND_TIMEZONE_ALT
" Get or set current timezone\r\n");
Expand All @@ -22,6 +23,7 @@ void totp_cli_command_timezone_docopt_arguments() {
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_TIMEZONE_ARG_TIMEZONE
" Timezone offset in hours to be set\r\n");
}
#endif

void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
if(!totp_cli_ensure_authenticated(plugin_state, cli)) {
Expand Down
5 changes: 4 additions & 1 deletion totp/cli/commands/timezone/timezone.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

#include <cli/cli.h>
#include "../../../types/plugin_state.h"
#include "../../../config/app/config.h"

#define TOTP_CLI_COMMAND_TIMEZONE "timezone"
#define TOTP_CLI_COMMAND_TIMEZONE_ALT "tz"

void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli);
#ifdef TOTP_CLI_RICH_HELP_ENABLED
void totp_cli_command_timezone_docopt_commands();
void totp_cli_command_timezone_docopt_usage();
void totp_cli_command_timezone_docopt_arguments();
void totp_cli_command_timezone_docopt_arguments();
#endif
Loading

0 comments on commit 89fa750

Please sign in to comment.