Quellcode durchsuchen

Merge totp from https://github.com/akopachov/flipper-zero_authenticator

Willy-JL vor 2 Jahren
Ursprung
Commit
d04366552a

+ 1 - 1
totp/application.fam

@@ -7,7 +7,7 @@ App(
     requires=["gui", "cli", "dialogs", "storage", "input", "notification", "bt"],
     stack_size=2 * 1024,
     order=20,
-    fap_version="5.50",
+    fap_version="5.60",
     fap_author="Alexander Kopachov (@akopachov)",
     fap_description="Software-based TOTP/HOTP authenticator for Flipper Zero device",
     fap_weburl="https://github.com/akopachov/flipper-zero_authenticator",

+ 26 - 7
totp/ui/scenes/add_new_token/totp_scene_add_new_token.c

@@ -62,7 +62,8 @@ static void update_duration_text(SceneState* scene_state) {
 
 static TotpIteratorUpdateTokenResult add_token_handler(TokenInfo* tokenInfo, const void* context) {
     const struct TotpAddContext* context_t = context;
-    if(sscanf(context_t->scene_state->initial_counter, "%" PRIu64, &tokenInfo->counter) != 1) {
+    if(context_t->scene_state->type == TokenTypeHOTP &&
+       sscanf(context_t->scene_state->initial_counter, "%" PRIu64, &tokenInfo->counter) != 1) {
         return TotpIteratorUpdateTokenResultInvalidCounter;
     }
 
@@ -264,15 +265,24 @@ bool totp_scene_add_new_token_handle_event(
                     RollOverflowBehaviorRoll);
             } else if(scene_state->selected_control == TokenLengthSelect) {
                 totp_roll_value_uint8_t(
-                    &scene_state->digits_count_index, 1, 0, 2, RollOverflowBehaviorRoll);
+                    &scene_state->digits_count_index,
+                    1,
+                    0,
+                    COUNT_OF(TOKEN_DIGITS_TEXT_LIST) - 1,
+                    RollOverflowBehaviorRoll);
             } else if(
                 scene_state->selected_control == TokenDurationOrCounterSelect &&
                 scene_state->type == TokenTypeTOTP) {
                 totp_roll_value_uint8_t(
-                    &scene_state->duration, 15, 15, 255, RollOverflowBehaviorStop);
+                    &scene_state->duration, 15, 15, UINT8_MAX, RollOverflowBehaviorStop);
                 update_duration_text(scene_state);
             } else if(scene_state->selected_control == TokenTypeSelect) {
-                totp_roll_value_uint8_t(&scene_state->type, 1, 0, 1, RollOverflowBehaviorRoll);
+                totp_roll_value_uint8_t(
+                    &scene_state->type,
+                    1,
+                    0,
+                    COUNT_OF(TOKEN_TYPE_LIST) - 1,
+                    RollOverflowBehaviorRoll);
             }
             break;
         case InputKeyLeft:
@@ -285,15 +295,24 @@ bool totp_scene_add_new_token_handle_event(
                     RollOverflowBehaviorRoll);
             } else if(scene_state->selected_control == TokenLengthSelect) {
                 totp_roll_value_uint8_t(
-                    &scene_state->digits_count_index, -1, 0, 2, RollOverflowBehaviorRoll);
+                    &scene_state->digits_count_index,
+                    -1,
+                    0,
+                    COUNT_OF(TOKEN_DIGITS_TEXT_LIST) - 1,
+                    RollOverflowBehaviorRoll);
             } else if(
                 scene_state->selected_control == TokenDurationOrCounterSelect &&
                 scene_state->type == TokenTypeTOTP) {
                 totp_roll_value_uint8_t(
-                    &scene_state->duration, -15, 15, 255, RollOverflowBehaviorStop);
+                    &scene_state->duration, -15, 15, UINT8_MAX, RollOverflowBehaviorStop);
                 update_duration_text(scene_state);
             } else if(scene_state->selected_control == TokenTypeSelect) {
-                totp_roll_value_uint8_t(&scene_state->type, -1, 0, 1, RollOverflowBehaviorRoll);
+                totp_roll_value_uint8_t(
+                    &scene_state->type,
+                    -1,
+                    0,
+                    COUNT_OF(TOKEN_TYPE_LIST) - 1,
+                    RollOverflowBehaviorRoll);
             }
             break;
         case InputKeyOk:

+ 6 - 12
totp/ui/scenes/app_settings/totp_app_settings.c

@@ -17,12 +17,6 @@
 
 #include <assets_icons.h>
 
-#ifdef TOTP_BADBT_AUTOMATION_ENABLED
-#define AUTOMATION_LIST_MAX_INDEX (3)
-#else
-#define AUTOMATION_LIST_MAX_INDEX (1)
-#endif
-#define BAD_KB_LAYOUT_LIST_MAX_INDEX (2)
 #define FONT_TEST_STR_LENGTH (7)
 
 static const char* YES_NO_LIST[] = {"NO", "YES"};
@@ -75,9 +69,9 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) {
     scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound;
     scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro;
     scene_state->automation_method =
-        MIN(plugin_state->automation_method, AUTOMATION_LIST_MAX_INDEX);
+        MIN(plugin_state->automation_method, COUNT_OF(AUTOMATION_LIST) - 1);
     scene_state->automation_kb_layout =
-        MIN(plugin_state->automation_kb_layout, BAD_KB_LAYOUT_LIST_MAX_INDEX);
+        MIN(plugin_state->automation_kb_layout, COUNT_OF(BAD_KB_LAYOUT_LIST) - 1);
 
     scene_state->total_fonts_count = totp_font_provider_get_fonts_count();
     scene_state->active_font_index = plugin_state->active_font_index;
@@ -290,14 +284,14 @@ bool totp_scene_app_settings_handle_event(
                     &scene_state->automation_method,
                     1,
                     0,
-                    AUTOMATION_LIST_MAX_INDEX,
+                    COUNT_OF(AUTOMATION_LIST) - 1,
                     RollOverflowBehaviorRoll);
             } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
                 totp_roll_value_uint8_t(
                     &scene_state->automation_kb_layout,
                     1,
                     0,
-                    BAD_KB_LAYOUT_LIST_MAX_INDEX,
+                    COUNT_OF(BAD_KB_LAYOUT_LIST) - 1,
                     RollOverflowBehaviorRoll);
             }
             break;
@@ -326,14 +320,14 @@ bool totp_scene_app_settings_handle_event(
                     &scene_state->automation_method,
                     -1,
                     0,
-                    AUTOMATION_LIST_MAX_INDEX,
+                    COUNT_OF(AUTOMATION_LIST) - 1,
                     RollOverflowBehaviorRoll);
             } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
                 totp_roll_value_uint8_t(
                     &scene_state->automation_kb_layout,
                     -1,
                     0,
-                    BAD_KB_LAYOUT_LIST_MAX_INDEX,
+                    COUNT_OF(BAD_KB_LAYOUT_LIST) - 1,
                     RollOverflowBehaviorRoll);
             }
             break;

+ 1 - 1
totp/version.h

@@ -1,5 +1,5 @@
 #pragma once
 
 #define TOTP_APP_VERSION_MAJOR (5)
-#define TOTP_APP_VERSION_MINOR (5)
+#define TOTP_APP_VERSION_MINOR (6)
 #define TOTP_APP_VERSION_PATCH (0)