Skip to content

Commit

Permalink
Implemented #49 (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Dec 21, 2022
1 parent 7bb00ea commit b718e64
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 247 deletions.
3 changes: 3 additions & 0 deletions cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
TOTP_CLI_PRINTF( \
"Invalid command arguments. use \"help\" command to get list of available commands")

#define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
TOTP_CLI_PRINTF("An error has occurred during updating config file\r\n")

/**
* @brief Checks whether user is authenticated and entered correct PIN.
* If user is not authenticated it prompts user to enter correct PIN to authenticate.
Expand Down
8 changes: 5 additions & 3 deletions cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl

TOTP_LIST_INIT_OR_ADD(plugin_state->tokens_list, token_info, furi_check);
plugin_state->tokens_count++;
totp_config_file_save_new_token(token_info);
if(totp_config_file_save_new_token(token_info) == TotpConfigFileUpdateSuccess) {
TOTP_CLI_PRINTF("Token \"%s\" has been successfully added\r\n", token_info->name);
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}

if(load_generate_token_scene) {
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
}

TOTP_CLI_PRINTF("Token \"%s\" has been successfully added\r\n", token_info->name);
}
11 changes: 7 additions & 4 deletions cli/commands/delete/delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
plugin_state->tokens_list = list_remove(plugin_state->tokens_list, list_node);
plugin_state->tokens_count--;

totp_full_save_config_file(plugin_state);
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
TOTP_CLI_PRINTF("Token \"%s\" has been successfully deleted\r\n", token_info->name);
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}

token_info_free(token_info);

if(activate_generate_token_scene) {
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
}

TOTP_CLI_PRINTF("Token \"%s\" has been successfully deleted\r\n", token_info->name);
token_info_free(token_info);
} else {
TOTP_CLI_PRINTF("User not confirmed\r\n");
}
Expand Down
14 changes: 7 additions & 7 deletions cli/commands/move/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
}

if(token_updated) {
totp_full_save_config_file(plugin_state);
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
TOTP_CLI_PRINTF("Token \"%s\" has been successfully updated\r\n", token_info->name);
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}
} else {
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
}

if(activate_generate_token_scene) {
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
}

if(token_updated) {
TOTP_CLI_PRINTF("Token \"%s\" has been successfully updated\r\n", token_info->name);
} else {
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
}

furi_string_free(temp_str);
}
13 changes: 8 additions & 5 deletions cli/commands/notification/notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString*
}

plugin_state->notification_method = new_method;
totp_config_file_update_notification_method(new_method);
if(totp_config_file_update_notification_method(new_method) ==
TotpConfigFileUpdateSuccess) {
TOTP_CLI_PRINTF("Notification method is set to ");
totp_cli_command_notification_print_method(new_method);
cli_nl();
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}

if(previous_scene != TotpSceneNone) {
totp_scene_director_activate_scene(plugin_state, previous_scene, NULL);
}

TOTP_CLI_PRINTF("Notification method is set to ");
totp_cli_command_notification_print_method(new_method);
cli_nl();
} else {
TOTP_CLI_PRINTF("Current notification method is ");
totp_cli_command_notification_print_method(plugin_state->notification_method);
Expand Down
25 changes: 17 additions & 8 deletions cli/commands/pin/pin.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,14 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
plugin_state->crypto_verify_data = NULL;
}

totp_crypto_seed_iv(
plugin_state, new_pin_length > 0 ? &new_pin[0] : NULL, new_pin_length);
if(!totp_crypto_seed_iv(
plugin_state, new_pin_length > 0 ? &new_pin[0] : NULL, new_pin_length)) {
memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE);
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
break;
}

memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE);

TOTP_LIST_FOREACH(plugin_state->tokens_list, node, {
TokenInfo* token_info = node->data;
Expand All @@ -152,15 +158,18 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
free(plain_token);
});

totp_full_save_config_file(plugin_state);

TOTP_CLI_DELETE_LAST_LINE();

if(do_change) {
TOTP_CLI_PRINTF("PIN has been successfully changed\r\n");
} else if(do_remove) {
TOTP_CLI_PRINTF("PIN has been successfully removed\r\n");
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
if(do_change) {
TOTP_CLI_PRINTF("PIN has been successfully changed\r\n");
} else if(do_remove) {
TOTP_CLI_PRINTF("PIN has been successfully removed\r\n");
}
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}

} while(false);

if(load_generate_token_scene) {
Expand Down
7 changes: 5 additions & 2 deletions cli/commands/timezone/timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg
float tz = strtof(furi_string_get_cstr(temp_str), NULL);
if(tz >= -12.75f && tz <= 12.75f) {
plugin_state->timezone_offset = tz;
totp_config_file_update_timezone_offset(tz);
TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
if(totp_config_file_update_timezone_offset(tz) == TotpConfigFileUpdateSuccess) {
TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
} else {
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
}
if(plugin_state->current_scene == TotpSceneGenerateToken) {
totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
Expand Down
Loading

0 comments on commit b718e64

Please sign in to comment.