mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-07-28 01:58:11 -07:00
totp fix to latest
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "commands/help/help.h"
|
||||
#include "commands/move/move.h"
|
||||
#include "commands/pin/pin.h"
|
||||
#include "commands/notification/notification.h"
|
||||
|
||||
static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
|
||||
TOTP_CLI_PRINTF(
|
||||
@@ -52,6 +53,8 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) {
|
||||
totp_cli_command_move_handle(plugin_state, args, cli);
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_PIN) == 0) {
|
||||
totp_cli_command_pin_handle(plugin_state, args, cli);
|
||||
} else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_NOTIFICATION) == 0) {
|
||||
totp_cli_command_notification_handle(plugin_state, args, cli);
|
||||
} else {
|
||||
totp_cli_print_unknown_command(cmd);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#define TOTP_CLI_COMMAND_NAME "totp"
|
||||
|
||||
#define DOCOPT_ARGUMENT(arg) "<" arg ">"
|
||||
#define DOCOPT_MULTIPLE(arg) arg "..."
|
||||
#define DOCOPT_OPTIONAL(param) "[" param "]"
|
||||
#define DOCOPT_REQUIRED(param) "(" param ")"
|
||||
#define DOCOPT_OPTION(option, value) option " " value
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "../../../lib/list/list.h"
|
||||
#include "../../../types/token_info.h"
|
||||
#include "../../../services/config/config.h"
|
||||
#include "../../../services/convert/convert.h"
|
||||
#include "../../cli_helpers.h"
|
||||
#include "../../../ui/scene_director.h"
|
||||
|
||||
@@ -14,21 +15,6 @@
|
||||
#define TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "-d"
|
||||
#define TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX "-u"
|
||||
|
||||
static bool token_info_set_digits_from_str(TokenInfo* token_info, const FuriString* str) {
|
||||
switch(furi_string_get_char(str, 0)) {
|
||||
case '6':
|
||||
token_info->digits = TOTP_6_DIGITS;
|
||||
return true;
|
||||
case '8':
|
||||
token_info->digits = TOTP_8_DIGITS;
|
||||
return true;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) {
|
||||
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
|
||||
token_info->algo = SHA1;
|
||||
@@ -73,6 +59,7 @@ void totp_cli_command_add_docopt_options() {
|
||||
DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_ADD_ARG_ALGO)) " Token hashing algorithm.\r\n");
|
||||
TOTP_CLI_PRINTF(
|
||||
" Could be one of: sha1, sha256, sha512 " DOCOPT_DEFAULT("sha1") "\r\n");
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF(" " DOCOPT_OPTION(
|
||||
TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX,
|
||||
DOCOPT_ARGUMENT(
|
||||
@@ -164,7 +151,8 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
|
||||
TOTP_CLI_PRINTF(
|
||||
"Missed value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
|
||||
"\"\r\n");
|
||||
} else if(!token_info_set_digits_from_str(token_info, temp_str)) {
|
||||
} else if(!token_info_set_digits_from_int(
|
||||
token_info, CONVERT_CHAR_TO_DIGIT(furi_string_get_char(temp_str, 0)))) {
|
||||
TOTP_CLI_PRINTF(
|
||||
"\"%s\" is incorrect value for argument \"" TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX
|
||||
"\"\r\n",
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "../timezone/timezone.h"
|
||||
#include "../move/move.h"
|
||||
#include "../pin/pin.h"
|
||||
#include "../notification/notification.h"
|
||||
|
||||
void totp_cli_command_help_docopt_commands() {
|
||||
TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_HELP ", " TOTP_CLI_COMMAND_HELP_ALT
|
||||
@@ -27,6 +28,7 @@ void totp_cli_command_help_handle() {
|
||||
totp_cli_command_timezone_docopt_usage();
|
||||
totp_cli_command_move_docopt_usage();
|
||||
totp_cli_command_pin_docopt_usage();
|
||||
totp_cli_command_notification_docopt_usage();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Commands:\r\n");
|
||||
totp_cli_command_help_docopt_commands();
|
||||
@@ -36,11 +38,13 @@ void totp_cli_command_help_handle() {
|
||||
totp_cli_command_timezone_docopt_commands();
|
||||
totp_cli_command_move_docopt_commands();
|
||||
totp_cli_command_pin_docopt_commands();
|
||||
totp_cli_command_notification_docopt_commands();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Arguments:\r\n");
|
||||
totp_cli_command_add_docopt_arguments();
|
||||
totp_cli_command_delete_docopt_arguments();
|
||||
totp_cli_command_timezone_docopt_arguments();
|
||||
totp_cli_command_notification_docopt_arguments();
|
||||
cli_nl();
|
||||
TOTP_CLI_PRINTF("Options:\r\n");
|
||||
totp_cli_command_add_docopt_options();
|
||||
|
||||
@@ -20,19 +20,6 @@ static char* get_algo_as_cstr(TokenHashAlgo algo) {
|
||||
return "UNKNOWN";
|
||||
}
|
||||
|
||||
static uint8_t get_digits_as_int(TokenDigitsCount digits) {
|
||||
switch(digits) {
|
||||
case TOTP_6_DIGITS:
|
||||
return 6;
|
||||
case TOTP_8_DIGITS:
|
||||
return 8;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 6;
|
||||
}
|
||||
|
||||
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");
|
||||
@@ -59,13 +46,12 @@ void totp_cli_command_list_handle(PluginState* plugin_state, Cli* cli) {
|
||||
uint16_t index = 1;
|
||||
TOTP_LIST_FOREACH(plugin_state->tokens_list, node, {
|
||||
TokenInfo* token_info = (TokenInfo*)node->data;
|
||||
token_info_get_digits_count(token_info);
|
||||
TOTP_CLI_PRINTF(
|
||||
"| %-3" PRIu16 " | %-27.27s | %-6s | %-6" PRIu8 " |\r\n",
|
||||
index,
|
||||
token_info->name,
|
||||
get_algo_as_cstr(token_info->algo),
|
||||
get_digits_as_int(token_info->digits));
|
||||
token_info->digits);
|
||||
index++;
|
||||
});
|
||||
TOTP_CLI_PRINTF("+-----+-----------------------------+--------+--------+\r\n");
|
||||
|
||||
@@ -21,8 +21,6 @@ void totp_cli_command_timezone_docopt_usage() {
|
||||
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");
|
||||
TOTP_CLI_PRINTF(
|
||||
" If not provided then current timezone offset will be printed\r\n");
|
||||
}
|
||||
|
||||
void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* args, Cli* cli) {
|
||||
|
||||
Reference in New Issue
Block a user