@@ -22,8 +22,11 @@ enum TotpIteratorUpdateTokenResultsEx {
2222 TotpIteratorUpdateTokenResultInvalidArguments = 3
2323};
2424
25- static bool
26- totp_cli_try_read_name (TokenInfo * token_info , const FuriString * arg , FuriString * args , bool * parsed ) {
25+ static bool totp_cli_try_read_name (
26+ TokenInfo * token_info ,
27+ const FuriString * arg ,
28+ FuriString * args ,
29+ bool * parsed ) {
2730 if (furi_string_cmpi_str (arg , TOTP_CLI_COMMAND_ARG_NAME_PREFIX ) == 0 ) {
2831 if (!args_read_probably_quoted_string_and_trim (args , token_info -> name ) ||
2932 furi_string_empty (token_info -> name )) {
@@ -48,14 +51,15 @@ static bool totp_cli_try_read_change_secret_flag(const FuriString* arg, bool* pa
4851 return false;
4952}
5053
51- static TotpIteratorUpdateTokenResult update_token_handler (TokenInfo * token_info , const void * context ) {
54+ static TotpIteratorUpdateTokenResult
55+ update_token_handler (TokenInfo * token_info , const void * context ) {
5256 const struct TotpUpdateContext * context_t = context ;
5357
5458 // Read optional arguments
5559 FuriString * temp_str = furi_string_alloc ();
5660 bool mask_user_input = true;
5761 bool update_token_secret = false;
58- PlainTokenSecretEncoding token_secret_encoding = PLAIN_TOKEN_ENCODING_BASE32 ;
62+ PlainTokenSecretEncoding token_secret_encoding = PlainTokenSecretEncodingBase32 ;
5963 while (args_read_string_and_trim (context_t -> args , temp_str )) {
6064 bool parsed = false;
6165 if (!totp_cli_try_read_name (token_info , temp_str , context_t -> args , & parsed ) &&
@@ -82,17 +86,17 @@ static TotpIteratorUpdateTokenResult update_token_handler(TokenInfo* token_info,
8286 TOTP_CLI_PRINTF ("Enter token secret and confirm with [ENTER]\r\n" );
8387 bool token_secret_read = totp_cli_read_line (context_t -> cli , temp_str , mask_user_input );
8488 totp_cli_delete_last_line ();
85- if (!token_secret_read ) {
89+ if (!token_secret_read ) {
8690 furi_string_secure_free (temp_str );
8791 return TotpIteratorUpdateTokenResultCancelled ;
8892 }
8993
90- if (!token_info_set_secret (
91- token_info ,
92- furi_string_get_cstr (temp_str ),
93- furi_string_size (temp_str ),
94- token_secret_encoding ,
95- context_t -> iv )) {
94+ if (!token_info_set_secret (
95+ token_info ,
96+ furi_string_get_cstr (temp_str ),
97+ furi_string_size (temp_str ),
98+ token_secret_encoding ,
99+ context_t -> iv )) {
96100 furi_string_secure_free (temp_str );
97101 return TotpIteratorUpdateTokenResultInvalidSecret ;
98102 }
@@ -131,7 +135,8 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args,
131135 return ;
132136 }
133137
134- TokenInfoIteratorContext * iterator_context = totp_config_get_token_iterator_context (plugin_state );
138+ TokenInfoIteratorContext * iterator_context =
139+ totp_config_get_token_iterator_context (plugin_state );
135140
136141 int token_number ;
137142 if (!args_read_int_and_trim (args , & token_number ) || token_number <= 0 ||
@@ -145,23 +150,26 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args,
145150 size_t previous_index = totp_token_info_iterator_get_current_token_index (iterator_context );
146151 totp_token_info_iterator_go_to (iterator_context , token_number - 1 );
147152
148- struct TotpUpdateContext update_context = { .args = args , .cli = cli , .iv = & plugin_state -> iv [0 ] };
149- TotpIteratorUpdateTokenResult update_result = totp_token_info_iterator_update_current_token (iterator_context , & update_token_handler , & update_context );
150-
153+ struct TotpUpdateContext update_context = {
154+ .args = args , .cli = cli , .iv = & plugin_state -> iv [0 ]};
155+ TotpIteratorUpdateTokenResult update_result = totp_token_info_iterator_update_current_token (
156+ iterator_context , & update_token_handler , & update_context );
157+
151158 if (update_result == TotpIteratorUpdateTokenResultSuccess ) {
152159 TOTP_CLI_PRINTF_SUCCESS (
153160 "Token \"%s\" has been successfully updated\r\n" ,
154- furi_string_get_cstr (totp_token_info_iterator_get_current_token (iterator_context )-> name ));
155- } else if (update_result == TotpIteratorUpdateTokenResultInvalidArguments ) {
161+ furi_string_get_cstr (
162+ totp_token_info_iterator_get_current_token (iterator_context )-> name ));
163+ } else if (update_result == TotpIteratorUpdateTokenResultInvalidArguments ) {
156164 totp_cli_print_invalid_arguments ();
157- } else if (update_result == TotpIteratorUpdateTokenResultCancelled ) {
165+ } else if (update_result == TotpIteratorUpdateTokenResultCancelled ) {
158166 TOTP_CLI_PRINTF_INFO ("Cancelled by user\r\n" );
159- } else if (update_result == TotpIteratorUpdateTokenResultInvalidSecret ) {
167+ } else if (update_result == TotpIteratorUpdateTokenResultInvalidSecret ) {
160168 TOTP_CLI_PRINTF_ERROR ("Token secret seems to be invalid and can not be parsed\r\n" );
161- } else if (update_result == TotpIteratorUpdateTokenResultFileUpdateFailed ) {
169+ } else if (update_result == TotpIteratorUpdateTokenResultFileUpdateFailed ) {
162170 totp_cli_print_error_updating_config_file ();
163171 }
164-
172+
165173 totp_token_info_iterator_go_to (iterator_context , previous_index );
166174 TOTP_CLI_UNLOCK_UI (plugin_state );
167175}
0 commit comments