Skip to content

Commit 2dac83a

Browse files
authored
Implemented #49 (#50)
1 parent 3ef8057 commit 2dac83a

21 files changed

+593
-249
lines changed

totp/cli/cli_helpers.h

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
TOTP_CLI_PRINTF( \
3939
"Invalid command arguments. use \"help\" command to get list of available commands")
4040

41+
#define TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE() \
42+
TOTP_CLI_PRINTF("An error has occurred during updating config file\r\n")
43+
4144
/**
4245
* @brief Checks whether user is authenticated and entered correct PIN.
4346
* If user is not authenticated it prompts user to enter correct PIN to authenticate.

totp/cli/commands/add/add.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,13 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl
206206

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

211215
if(load_generate_token_scene) {
212216
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
213217
}
214-
215-
TOTP_CLI_PRINTF("Token \"%s\" has been successfully added\r\n", token_info->name);
216218
}

totp/cli/commands/delete/delete.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,17 @@ void totp_cli_command_delete_handle(PluginState* plugin_state, FuriString* args,
9393
plugin_state->tokens_list = list_remove(plugin_state->tokens_list, list_node);
9494
plugin_state->tokens_count--;
9595

96-
totp_full_save_config_file(plugin_state);
96+
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
97+
TOTP_CLI_PRINTF("Token \"%s\" has been successfully deleted\r\n", token_info->name);
98+
} else {
99+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
100+
}
101+
102+
token_info_free(token_info);
97103

98104
if(activate_generate_token_scene) {
99105
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
100106
}
101-
102-
TOTP_CLI_PRINTF("Token \"%s\" has been successfully deleted\r\n", token_info->name);
103-
token_info_free(token_info);
104107
} else {
105108
TOTP_CLI_PRINTF("User not confirmed\r\n");
106109
}

totp/cli/commands/move/move.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -147,18 +147,18 @@ void totp_cli_command_move_handle(PluginState* plugin_state, FuriString* args, C
147147
}
148148

149149
if(token_updated) {
150-
totp_full_save_config_file(plugin_state);
150+
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
151+
TOTP_CLI_PRINTF("Token \"%s\" has been successfully updated\r\n", token_info->name);
152+
} else {
153+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
154+
}
155+
} else {
156+
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
151157
}
152158

153159
if(activate_generate_token_scene) {
154160
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
155161
}
156162

157-
if(token_updated) {
158-
TOTP_CLI_PRINTF("Token \"%s\" has been successfully updated\r\n", token_info->name);
159-
} else {
160-
TOTP_CLI_PRINT_INVALID_ARGUMENTS();
161-
}
162-
163163
furi_string_free(temp_str);
164164
}

totp/cli/commands/notification/notification.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ void totp_cli_command_notification_handle(PluginState* plugin_state, FuriString*
8686
}
8787

8888
plugin_state->notification_method = new_method;
89-
totp_config_file_update_notification_method(new_method);
89+
if(totp_config_file_update_notification_method(new_method) ==
90+
TotpConfigFileUpdateSuccess) {
91+
TOTP_CLI_PRINTF("Notification method is set to ");
92+
totp_cli_command_notification_print_method(new_method);
93+
cli_nl();
94+
} else {
95+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
96+
}
9097

9198
if(previous_scene != TotpSceneNone) {
9299
totp_scene_director_activate_scene(plugin_state, previous_scene, NULL);
93100
}
94-
95-
TOTP_CLI_PRINTF("Notification method is set to ");
96-
totp_cli_command_notification_print_method(new_method);
97-
cli_nl();
98101
} else {
99102
TOTP_CLI_PRINTF("Current notification method is ");
100103
totp_cli_command_notification_print_method(plugin_state->notification_method);

totp/cli/commands/pin/pin.c

+17-8
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,14 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl
134134
plugin_state->crypto_verify_data = NULL;
135135
}
136136

137-
totp_crypto_seed_iv(
138-
plugin_state, new_pin_length > 0 ? &new_pin[0] : NULL, new_pin_length);
137+
if(!totp_crypto_seed_iv(
138+
plugin_state, new_pin_length > 0 ? &new_pin[0] : NULL, new_pin_length)) {
139+
memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE);
140+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
141+
break;
142+
}
143+
144+
memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE);
139145

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

155-
totp_full_save_config_file(plugin_state);
156-
157161
TOTP_CLI_DELETE_LAST_LINE();
158162

159-
if(do_change) {
160-
TOTP_CLI_PRINTF("PIN has been successfully changed\r\n");
161-
} else if(do_remove) {
162-
TOTP_CLI_PRINTF("PIN has been successfully removed\r\n");
163+
if(totp_full_save_config_file(plugin_state) == TotpConfigFileUpdateSuccess) {
164+
if(do_change) {
165+
TOTP_CLI_PRINTF("PIN has been successfully changed\r\n");
166+
} else if(do_remove) {
167+
TOTP_CLI_PRINTF("PIN has been successfully removed\r\n");
168+
}
169+
} else {
170+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
163171
}
172+
164173
} while(false);
165174

166175
if(load_generate_token_scene) {

totp/cli/commands/timezone/timezone.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ void totp_cli_command_timezone_handle(PluginState* plugin_state, FuriString* arg
3333
float tz = strtof(furi_string_get_cstr(temp_str), NULL);
3434
if(tz >= -12.75f && tz <= 12.75f) {
3535
plugin_state->timezone_offset = tz;
36-
totp_config_file_update_timezone_offset(tz);
37-
TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
36+
if(totp_config_file_update_timezone_offset(tz) == TotpConfigFileUpdateSuccess) {
37+
TOTP_CLI_PRINTF("Timezone is set to %f\r\n", tz);
38+
} else {
39+
TOTP_CLI_PRINT_ERROR_UPDATING_CONFIG_FILE();
40+
}
3841
if(plugin_state->current_scene == TotpSceneGenerateToken) {
3942
totp_scene_director_activate_scene(plugin_state, TotpSceneNone, NULL);
4043
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);

0 commit comments

Comments
 (0)