@@ -22,8 +22,11 @@ enum TotpIteratorUpdateTokenResultsEx {
22
22
TotpIteratorUpdateTokenResultInvalidArguments = 3
23
23
};
24
24
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 ) {
27
30
if (furi_string_cmpi_str (arg , TOTP_CLI_COMMAND_ARG_NAME_PREFIX ) == 0 ) {
28
31
if (!args_read_probably_quoted_string_and_trim (args , token_info -> name ) ||
29
32
furi_string_empty (token_info -> name )) {
@@ -48,14 +51,15 @@ static bool totp_cli_try_read_change_secret_flag(const FuriString* arg, bool* pa
48
51
return false;
49
52
}
50
53
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 ) {
52
56
const struct TotpUpdateContext * context_t = context ;
53
57
54
58
// Read optional arguments
55
59
FuriString * temp_str = furi_string_alloc ();
56
60
bool mask_user_input = true;
57
61
bool update_token_secret = false;
58
- PlainTokenSecretEncoding token_secret_encoding = PLAIN_TOKEN_ENCODING_BASE32 ;
62
+ PlainTokenSecretEncoding token_secret_encoding = PlainTokenSecretEncodingBase32 ;
59
63
while (args_read_string_and_trim (context_t -> args , temp_str )) {
60
64
bool parsed = false;
61
65
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,
82
86
TOTP_CLI_PRINTF ("Enter token secret and confirm with [ENTER]\r\n" );
83
87
bool token_secret_read = totp_cli_read_line (context_t -> cli , temp_str , mask_user_input );
84
88
totp_cli_delete_last_line ();
85
- if (!token_secret_read ) {
89
+ if (!token_secret_read ) {
86
90
furi_string_secure_free (temp_str );
87
91
return TotpIteratorUpdateTokenResultCancelled ;
88
92
}
89
93
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 )) {
96
100
furi_string_secure_free (temp_str );
97
101
return TotpIteratorUpdateTokenResultInvalidSecret ;
98
102
}
@@ -131,7 +135,8 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args,
131
135
return ;
132
136
}
133
137
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 );
135
140
136
141
int token_number ;
137
142
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,
145
150
size_t previous_index = totp_token_info_iterator_get_current_token_index (iterator_context );
146
151
totp_token_info_iterator_go_to (iterator_context , token_number - 1 );
147
152
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
+
151
158
if (update_result == TotpIteratorUpdateTokenResultSuccess ) {
152
159
TOTP_CLI_PRINTF_SUCCESS (
153
160
"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 ) {
156
164
totp_cli_print_invalid_arguments ();
157
- } else if (update_result == TotpIteratorUpdateTokenResultCancelled ) {
165
+ } else if (update_result == TotpIteratorUpdateTokenResultCancelled ) {
158
166
TOTP_CLI_PRINTF_INFO ("Cancelled by user\r\n" );
159
- } else if (update_result == TotpIteratorUpdateTokenResultInvalidSecret ) {
167
+ } else if (update_result == TotpIteratorUpdateTokenResultInvalidSecret ) {
160
168
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 ) {
162
170
totp_cli_print_error_updating_config_file ();
163
171
}
164
-
172
+
165
173
totp_token_info_iterator_go_to (iterator_context , previous_index );
166
174
TOTP_CLI_UNLOCK_UI (plugin_state );
167
175
}
0 commit comments