Skip to content

Commit 526213c

Browse files
committed
Clang format ran
1 parent 0483d8f commit 526213c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+2121
-1846
lines changed

scenes/add_new_token/totp_input_text.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ void view_unlock_model(View* view) {
2929
}
3030

3131
static void commit_text_input_callback(void* context) {
32-
InputTextSceneState* text_input_state = (InputTextSceneState *)context;
33-
if (text_input_state->callback != 0) {
32+
InputTextSceneState* text_input_state = (InputTextSceneState*)context;
33+
if(text_input_state->callback != 0) {
3434
InputTextSceneCallbackResult* result = malloc(sizeof(InputTextSceneCallbackResult));
3535
result->user_input_length = strlen(text_input_state->text_input_buffer);
3636
result->user_input = malloc(result->user_input_length + 1);

scenes/add_new_token/totp_scene_add_new_token.c

Lines changed: 140 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include "../generate_token/totp_scene_generate_token.h"
1212

1313
#define TOKEN_ALGO_LIST_LENGTH 3
14-
char* TOKEN_ALGO_LIST[] = { "SHA1", "SHA256", "SHA512" };
14+
char* TOKEN_ALGO_LIST[] = {"SHA1", "SHA256", "SHA512"};
1515
#define TOKEN_DIGITS_LIST_LENGTH 2
16-
char* TOKEN_DIGITS_LIST[] = { "6 digits", "8 digits" };
16+
char* TOKEN_DIGITS_LIST[] = {"6 digits", "8 digits"};
1717

1818
typedef enum {
1919
TokenNameTextBox,
@@ -62,7 +62,9 @@ static void on_token_secret_user_comitted(InputTextSceneCallbackResult* result)
6262
free(result);
6363
}
6464

65-
void totp_scene_add_new_token_activate(PluginState* plugin_state, const TokenAddEditSceneContext* context) {
65+
void totp_scene_add_new_token_activate(
66+
PluginState* plugin_state,
67+
const TokenAddEditSceneContext* context) {
6668
SceneState* scene_state = malloc(sizeof(SceneState));
6769
plugin_state->current_scene_state = scene_state;
6870
scene_state->token_name = "Name";
@@ -84,25 +86,52 @@ void totp_scene_add_new_token_activate(PluginState* plugin_state, const TokenAdd
8486

8587
scene_state->input_state = NULL;
8688

87-
if (context == NULL) {
89+
if(context == NULL) {
8890
scene_state->current_token_index = -1;
8991
} else {
9092
scene_state->current_token_index = context->current_token_index;
9193
}
9294
}
9395

9496
void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_state) {
95-
SceneState* scene_state = (SceneState *)plugin_state->current_scene_state;
96-
if (scene_state->input_started_at > 0) {
97+
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
98+
if(scene_state->input_started_at > 0) {
9799
totp_input_text_render(canvas, scene_state->input_state);
98100
return;
99101
}
100102

101-
ui_control_text_box_render(canvas, 10 - scene_state->screen_y_offset, scene_state->token_name, scene_state->selected_control == TokenNameTextBox);
102-
ui_control_text_box_render(canvas, 27 - scene_state->screen_y_offset, scene_state->token_secret, scene_state->selected_control == TokenSecretTextBox);
103-
ui_control_select_render(canvas, 0, 44 - scene_state->screen_y_offset, SCREEN_WIDTH, TOKEN_ALGO_LIST[scene_state->algo], scene_state->selected_control == TokenAlgoSelect);
104-
ui_control_select_render(canvas, 0, 63 - scene_state->screen_y_offset, SCREEN_WIDTH, TOKEN_DIGITS_LIST[scene_state->digits_count], scene_state->selected_control == TokenLengthSelect);
105-
ui_control_button_render(canvas, SCREEN_WIDTH_CENTER - 24, 85 - scene_state->screen_y_offset, 48, 13, "Confirm", scene_state->selected_control == ConfirmButton);
103+
ui_control_text_box_render(
104+
canvas,
105+
10 - scene_state->screen_y_offset,
106+
scene_state->token_name,
107+
scene_state->selected_control == TokenNameTextBox);
108+
ui_control_text_box_render(
109+
canvas,
110+
27 - scene_state->screen_y_offset,
111+
scene_state->token_secret,
112+
scene_state->selected_control == TokenSecretTextBox);
113+
ui_control_select_render(
114+
canvas,
115+
0,
116+
44 - scene_state->screen_y_offset,
117+
SCREEN_WIDTH,
118+
TOKEN_ALGO_LIST[scene_state->algo],
119+
scene_state->selected_control == TokenAlgoSelect);
120+
ui_control_select_render(
121+
canvas,
122+
0,
123+
63 - scene_state->screen_y_offset,
124+
SCREEN_WIDTH,
125+
TOKEN_DIGITS_LIST[scene_state->digits_count],
126+
scene_state->selected_control == TokenLengthSelect);
127+
ui_control_button_render(
128+
canvas,
129+
SCREEN_WIDTH_CENTER - 24,
130+
85 - scene_state->screen_y_offset,
131+
48,
132+
13,
133+
"Confirm",
134+
scene_state->selected_control == ConfirmButton);
106135

107136
canvas_set_color(canvas, ColorWhite);
108137
canvas_draw_box(canvas, 0, 0, SCREEN_WIDTH, 10);
@@ -113,7 +142,7 @@ void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_s
113142
}
114143

115144
void update_screen_y_offset(SceneState* scene_state) {
116-
if (scene_state->selected_control > TokenAlgoSelect) {
145+
if(scene_state->selected_control > TokenAlgoSelect) {
117146
scene_state->screen_y_offset = 35;
118147
} else {
119148
scene_state->screen_y_offset = 0;
@@ -122,121 +151,130 @@ void update_screen_y_offset(SceneState* scene_state) {
122151

123152
bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState* plugin_state) {
124153
if(event->type == EventTypeKey) {
125-
SceneState* scene_state = (SceneState *)plugin_state->current_scene_state;
126-
if (scene_state->input_started_at > 0 && furi_get_tick() - scene_state->input_started_at > 300) {
154+
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
155+
if(scene_state->input_started_at > 0 &&
156+
furi_get_tick() - scene_state->input_started_at > 300) {
127157
return totp_input_text_handle_event(event, scene_state->input_state);
128158
}
129159

130-
if (event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
160+
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
131161
return false;
132162
} else if(event->input.type == InputTypePress) {
133163
switch(event->input.key) {
134-
case InputKeyUp:
135-
if (scene_state->selected_control > TokenNameTextBox) {
136-
scene_state->selected_control--;
137-
update_screen_y_offset(scene_state);
164+
case InputKeyUp:
165+
if(scene_state->selected_control > TokenNameTextBox) {
166+
scene_state->selected_control--;
167+
update_screen_y_offset(scene_state);
168+
}
169+
break;
170+
case InputKeyDown:
171+
if(scene_state->selected_control < ConfirmButton) {
172+
scene_state->selected_control++;
173+
update_screen_y_offset(scene_state);
174+
}
175+
break;
176+
case InputKeyRight:
177+
if(scene_state->selected_control == TokenAlgoSelect) {
178+
if(scene_state->algo < SHA512) {
179+
scene_state->algo++;
180+
} else {
181+
scene_state->algo = SHA1;
138182
}
139-
break;
140-
case InputKeyDown:
141-
if (scene_state->selected_control < ConfirmButton) {
142-
scene_state->selected_control++;
143-
update_screen_y_offset(scene_state);
183+
} else if(scene_state->selected_control == TokenLengthSelect) {
184+
if(scene_state->digits_count < TOTP_8_DIGITS) {
185+
scene_state->digits_count++;
186+
} else {
187+
scene_state->digits_count = TOTP_6_DIGITS;
144188
}
145-
break;
146-
case InputKeyRight:
147-
if (scene_state->selected_control == TokenAlgoSelect) {
148-
if (scene_state->algo < SHA512) {
149-
scene_state->algo++;
150-
} else {
151-
scene_state->algo = SHA1;
152-
}
189+
}
190+
break;
191+
case InputKeyLeft:
192+
if(scene_state->selected_control == TokenAlgoSelect) {
193+
if(scene_state->algo > SHA1) {
194+
scene_state->algo--;
195+
} else {
196+
scene_state->algo = SHA512;
197+
}
198+
} else if(scene_state->selected_control == TokenLengthSelect) {
199+
if(scene_state->digits_count > TOTP_6_DIGITS) {
200+
scene_state->digits_count--;
201+
} else {
202+
scene_state->digits_count = TOTP_8_DIGITS;
153203
}
154-
else if (scene_state->selected_control == TokenLengthSelect) {
155-
if (scene_state->digits_count < TOTP_8_DIGITS) {
156-
scene_state->digits_count++;
157-
} else {
158-
scene_state->digits_count = TOTP_6_DIGITS;
159-
}
204+
}
205+
break;
206+
case InputKeyOk:
207+
switch(scene_state->selected_control) {
208+
case TokenNameTextBox:
209+
if(scene_state->input_state != NULL) {
210+
totp_input_text_free(scene_state->input_state);
160211
}
212+
scene_state->input_state =
213+
totp_input_text_activate(scene_state->token_name_input_context);
214+
scene_state->input_started_at = furi_get_tick();
161215
break;
162-
case InputKeyLeft:
163-
if (scene_state->selected_control == TokenAlgoSelect) {
164-
if (scene_state->algo > SHA1) {
165-
scene_state->algo--;
166-
} else {
167-
scene_state->algo = SHA512;
168-
}
169-
}
170-
else if (scene_state->selected_control == TokenLengthSelect) {
171-
if (scene_state->digits_count > TOTP_6_DIGITS) {
172-
scene_state->digits_count--;
173-
} else {
174-
scene_state->digits_count = TOTP_8_DIGITS;
175-
}
216+
case TokenSecretTextBox:
217+
if(scene_state->input_state != NULL) {
218+
totp_input_text_free(scene_state->input_state);
176219
}
220+
scene_state->input_state =
221+
totp_input_text_activate(scene_state->token_secret_input_context);
222+
scene_state->input_started_at = furi_get_tick();
177223
break;
178-
case InputKeyOk:
179-
switch (scene_state->selected_control) {
180-
case TokenNameTextBox:
181-
if (scene_state->input_state != NULL) {
182-
totp_input_text_free(scene_state->input_state);
183-
}
184-
scene_state->input_state = totp_input_text_activate(scene_state->token_name_input_context);
185-
scene_state->input_started_at = furi_get_tick();
186-
break;
187-
case TokenSecretTextBox:
188-
if (scene_state->input_state != NULL) {
189-
totp_input_text_free(scene_state->input_state);
190-
}
191-
scene_state->input_state = totp_input_text_activate(scene_state->token_secret_input_context);
192-
scene_state->input_started_at = furi_get_tick();
193-
break;
194-
case TokenAlgoSelect:
195-
break;
196-
case TokenLengthSelect:
197-
break;
198-
case ConfirmButton: {
199-
TokenInfo* tokenInfo = token_info_alloc();
200-
tokenInfo->name = malloc(scene_state->token_name_length + 1);
201-
strcpy(tokenInfo->name, scene_state->token_name);
202-
203-
token_info_set_secret(tokenInfo, scene_state->token_secret, scene_state->token_secret_length, &plugin_state->iv[0]);
224+
case TokenAlgoSelect:
225+
break;
226+
case TokenLengthSelect:
227+
break;
228+
case ConfirmButton: {
229+
TokenInfo* tokenInfo = token_info_alloc();
230+
tokenInfo->name = malloc(scene_state->token_name_length + 1);
231+
strcpy(tokenInfo->name, scene_state->token_name);
204232

205-
tokenInfo->algo = scene_state->algo;
206-
tokenInfo->digits = scene_state->digits_count;
207-
208-
if (plugin_state->tokens_list == NULL) {
209-
plugin_state->tokens_list = list_init_head(tokenInfo);
210-
} else {
211-
list_add(plugin_state->tokens_list, tokenInfo);
212-
}
213-
plugin_state->tokens_count++;
233+
token_info_set_secret(
234+
tokenInfo,
235+
scene_state->token_secret,
236+
scene_state->token_secret_length,
237+
&plugin_state->iv[0]);
214238

215-
totp_config_file_save_new_token(tokenInfo);
239+
tokenInfo->algo = scene_state->algo;
240+
tokenInfo->digits = scene_state->digits_count;
216241

217-
GenerateTokenSceneContext generate_scene_context = { .current_token_index = plugin_state->tokens_count - 1 };
218-
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, &generate_scene_context);
219-
break;
220-
}
221-
}
222-
break;
223-
case InputKeyBack:
224-
if (scene_state->current_token_index >= 0) {
225-
GenerateTokenSceneContext generate_scene_context = { .current_token_index = scene_state->current_token_index };
226-
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, &generate_scene_context);
242+
if(plugin_state->tokens_list == NULL) {
243+
plugin_state->tokens_list = list_init_head(tokenInfo);
227244
} else {
228-
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
245+
list_add(plugin_state->tokens_list, tokenInfo);
229246
}
247+
plugin_state->tokens_count++;
248+
249+
totp_config_file_save_new_token(tokenInfo);
250+
251+
GenerateTokenSceneContext generate_scene_context = {
252+
.current_token_index = plugin_state->tokens_count - 1};
253+
totp_scene_director_activate_scene(
254+
plugin_state, TotpSceneGenerateToken, &generate_scene_context);
230255
break;
256+
}
257+
}
258+
break;
259+
case InputKeyBack:
260+
if(scene_state->current_token_index >= 0) {
261+
GenerateTokenSceneContext generate_scene_context = {
262+
.current_token_index = scene_state->current_token_index};
263+
totp_scene_director_activate_scene(
264+
plugin_state, TotpSceneGenerateToken, &generate_scene_context);
265+
} else {
266+
totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken, NULL);
267+
}
268+
break;
231269
}
232270
}
233271
}
234272
return true;
235273
}
236274

237275
void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
238-
if (plugin_state->current_scene_state == NULL) return;
239-
SceneState* scene_state = (SceneState *)plugin_state->current_scene_state;
276+
if(plugin_state->current_scene_state == NULL) return;
277+
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
240278
free(scene_state->token_name);
241279
free(scene_state->token_secret);
242280

@@ -246,7 +284,7 @@ void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
246284
free(scene_state->token_secret_input_context->header_text);
247285
free(scene_state->token_secret_input_context);
248286

249-
if (scene_state->input_state != NULL) {
287+
if(scene_state->input_state != NULL) {
250288
totp_input_text_free(scene_state->input_state);
251289
}
252290

scenes/add_new_token/totp_scene_add_new_token.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ typedef struct {
1111
} TokenAddEditSceneContext;
1212

1313
void totp_scene_add_new_token_init(PluginState* plugin_state);
14-
void totp_scene_add_new_token_activate(PluginState* plugin_state, const TokenAddEditSceneContext* context);
14+
void totp_scene_add_new_token_activate(
15+
PluginState* plugin_state,
16+
const TokenAddEditSceneContext* context);
1517
void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_state);
1618
bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState* plugin_state);
1719
void totp_scene_add_new_token_deactivate(PluginState* plugin_state);

0 commit comments

Comments
 (0)