Explorar o código

Refactoring. Dropping useless methods #120 (#121)

Alexander Kopachov %!s(int64=2) %!d(string=hai) anos
pai
achega
5aff2f04ba

+ 3 - 3
features_config.h

@@ -5,9 +5,9 @@
 #define TOTP_AUTOMATION_ICONS_ENABLED
 
 // List of compatible firmwares
-#define TOTP_FIRMWARE_OFFICIAL_STABLE 1
-#define TOTP_FIRMWARE_OFFICIAL_DEV 2
-#define TOTP_FIRMWARE_XTREME 3
+#define TOTP_FIRMWARE_OFFICIAL_STABLE (1)
+#define TOTP_FIRMWARE_OFFICIAL_DEV (2)
+#define TOTP_FIRMWARE_XTREME (3)
 // End of list
 
 // Target firmware to build for

+ 1 - 1
lib/base32/base32.h

@@ -27,7 +27,7 @@
 
 #pragma once
 
-#include <stdlib.h>
+#include <stddef.h>
 #include <stdint.h>
 
 /**

+ 1 - 1
lib/base64/base64.c

@@ -22,7 +22,7 @@ static const uint8_t dtable[] = {0x3e, 0x80, 0x80, 0x80, 0x3f, 0x34, 0x35, 0x36,
                                  0x80, 0x80, 0x80, 0x80, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
                                  0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29,
                                  0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33};
-// "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
 static uint8_t get_dtable_value(uint8_t index) {
     return (index < 43 || index > 122) ? 0x80 : dtable[index - 43];
 }

+ 1 - 1
services/config/constants.h

@@ -1,7 +1,7 @@
 #pragma once
 
 #define CONFIG_FILE_HEADER "Flipper TOTP plugin config file"
-#define CONFIG_FILE_ACTUAL_VERSION 4
+#define CONFIG_FILE_ACTUAL_VERSION (4)
 
 #define TOTP_CONFIG_KEY_TIMEZONE "Timezone"
 #define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName"

+ 3 - 3
services/crypto/crypto.c

@@ -5,10 +5,10 @@
 #include "../../types/common.h"
 #include "memset_s.h"
 
-#define CRYPTO_KEY_SLOT 2
+#define CRYPTO_KEY_SLOT (2)
 #define CRYPTO_VERIFY_KEY "FFF_Crypto_pass"
-#define CRYPTO_VERIFY_KEY_LENGTH 16
-#define CRYPTO_ALIGNMENT_FACTOR 16
+#define CRYPTO_VERIFY_KEY_LENGTH (16)
+#define CRYPTO_ALIGNMENT_FACTOR (16)
 
 uint8_t* totp_crypto_encrypt(
     const uint8_t* plain_data,

+ 0 - 4
services/hmac/hmac_common.h

@@ -9,11 +9,7 @@
 #define _GLHMAC_CONCAT_(prefix, suffix) prefix##suffix
 #define _GLHMAC_CONCAT(prefix, suffix) _GLHMAC_CONCAT_(prefix, suffix)
 
-#if GL_HMAC_NAME == 5
-#define HMAC_ALG md5
-#else
 #define HMAC_ALG _GLHMAC_CONCAT(sha, GL_HMAC_NAME)
-#endif
 
 #define GL_HMAC_CTX _GLHMAC_CONCAT(HMAC_ALG, _ctx)
 #define GL_HMAC_FN _GLHMAC_CONCAT(hmac_, HMAC_ALG)

+ 3 - 3
totp_app.c

@@ -21,7 +21,7 @@
 #include "services/crypto/crypto.h"
 #include "cli/cli.h"
 
-#define IDLE_TIMEOUT 60000
+#define IDLE_TIMEOUT (60000)
 
 static void render_callback(Canvas* const canvas, void* ctx) {
     furi_assert(ctx);
@@ -97,6 +97,7 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
     plugin_state->gui = furi_record_open(RECORD_GUI);
     plugin_state->notification_app = furi_record_open(RECORD_NOTIFICATION);
     plugin_state->dialogs_app = furi_record_open(RECORD_DIALOGS);
+    memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE);
 
     if(totp_config_file_load_base(plugin_state) != TotpConfigFileOpenSuccess) {
         totp_dialogs_config_loading_error(plugin_state);
@@ -162,7 +163,7 @@ int32_t totp_app() {
     }
 
     TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state, event_queue);
-    totp_scene_director_init_scenes(plugin_state);
+
     if(!totp_activate_initial_scene(plugin_state)) {
         FURI_LOG_E(LOGGING_TAG, "An error ocurred during activating initial scene\r\n");
         totp_plugin_state_free(plugin_state);
@@ -210,7 +211,6 @@ int32_t totp_app() {
 
     totp_cli_unregister_command_handler(cli_context);
     totp_scene_director_deactivate_active_scene(plugin_state);
-    totp_scene_director_dispose(plugin_state);
 
     view_port_enabled_set(view_port, false);
     gui_remove_view_port(plugin_state->gui, view_port);

+ 1 - 1
types/plugin_state.h

@@ -12,7 +12,7 @@
 #include "../workers/bt_type_code/bt_type_code.h"
 #endif
 
-#define TOTP_IV_SIZE 16
+#define TOTP_IV_SIZE (16)
 
 /**
  * @brief Application state structure

+ 14 - 3
types/token_info.h

@@ -4,13 +4,13 @@
 #include <stdbool.h>
 #include <furi/furi.h>
 
-#define TOTP_TOKEN_DURATION_DEFAULT 30
+#define TOTP_TOKEN_DURATION_DEFAULT (30)
 
 #define TOTP_TOKEN_ALGO_SHA1_NAME "sha1"
 #define TOTP_TOKEN_ALGO_STEAM_NAME "steam"
 #define TOTP_TOKEN_ALGO_SHA256_NAME "sha256"
 #define TOTP_TOKEN_ALGO_SHA512_NAME "sha512"
-#define TOTP_TOKEN_MAX_LENGTH 255
+#define TOTP_TOKEN_MAX_LENGTH (255)
 
 #define PLAIN_TOKEN_ENCODING_BASE32_NAME "base32"
 #define PLAIN_TOKEN_ENCODING_BASE64_NAME "base64"
@@ -95,12 +95,23 @@ enum TokenAutomationFeatures {
     TOKEN_AUTOMATION_FEATURE_TYPE_SLOWER = 0b100
 };
 
+/**
+ * @brief Plain token secret encodings.
+ */
 enum PlainTokenSecretEncodings {
+
+    /**
+     * @brief Base32 encoding
+     */
     PLAIN_TOKEN_ENCODING_BASE32 = 0,
+
+    /**
+     * @brief Base64 encoding
+     */
     PLAIN_TOKEN_ENCODING_BASE64 = 1
 };
 
-#define TOTP_TOKEN_DIGITS_MAX_COUNT 8
+#define TOTP_TOKEN_DIGITS_MAX_COUNT (8)
 
 /**
  * @brief TOTP token information

+ 2 - 2
ui/constants.h

@@ -1,6 +1,6 @@
 #pragma once
 
-#define SCREEN_WIDTH 128
-#define SCREEN_HEIGHT 64
+#define SCREEN_WIDTH (128)
+#define SCREEN_HEIGHT (64)
 #define SCREEN_WIDTH_CENTER (SCREEN_WIDTH >> 1)
 #define SCREEN_HEIGHT_CENTER (SCREEN_HEIGHT >> 1)

+ 1 - 0
ui/fonts/mode-nine/mode-nine.c

@@ -1,4 +1,5 @@
 #include "mode-nine.h"
+#include <stdint.h>
 
 /* GENERATED BY https://github.com/pavius/the-dot-factory */
 

+ 0 - 1
ui/fonts/mode-nine/mode-nine.h

@@ -3,7 +3,6 @@
 /* GENERATED BY https://github.com/pavius/the-dot-factory */
 
 #include "../font-info.h"
-#include <stdint.h>
 
 /* Font data for ModeNine 15pt */
 extern const FONT_INFO modeNine_15ptFontInfo;

+ 0 - 16
ui/scene_director.c

@@ -62,14 +62,6 @@ void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state
     }
 }
 
-void totp_scene_director_init_scenes(PluginState* const plugin_state) {
-    totp_scene_authenticate_init(plugin_state);
-    totp_scene_generate_token_init(plugin_state);
-    totp_scene_add_new_token_init(plugin_state);
-    totp_scene_token_menu_init(plugin_state);
-    totp_scene_app_settings_init(plugin_state);
-}
-
 void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state) {
     switch(plugin_state->current_scene) {
     case TotpSceneGenerateToken:
@@ -94,14 +86,6 @@ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_
     }
 }
 
-void totp_scene_director_dispose(const PluginState* const plugin_state) {
-    totp_scene_generate_token_free(plugin_state);
-    totp_scene_authenticate_free(plugin_state);
-    totp_scene_add_new_token_free(plugin_state);
-    totp_scene_token_menu_free(plugin_state);
-    totp_scene_app_settings_free(plugin_state);
-}
-
 bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state) {
     bool processing = true;
     switch(plugin_state->current_scene) {

+ 0 - 12
ui/scene_director.h

@@ -22,12 +22,6 @@ void totp_scene_director_activate_scene(
  */
 void totp_scene_director_deactivate_active_scene(PluginState* const plugin_state);
 
-/**
- * @brief Initializes all the available scenes
- * @param plugin_state application state
- */
-void totp_scene_director_init_scenes(PluginState* const plugin_state);
-
 /**
  * @brief Renders current scene
  * @param canvas canvas to render at
@@ -35,12 +29,6 @@ void totp_scene_director_init_scenes(PluginState* const plugin_state);
  */
 void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_state);
 
-/**
- * @brief Disposes all the available scenes
- * @param plugin_state application state
- */
-void totp_scene_director_dispose(const PluginState* const plugin_state);
-
 /**
  * @brief Handles application event for the current scene
  * @param event event to be handled

+ 2 - 2
ui/scenes/add_new_token/totp_input_text.h

@@ -6,6 +6,8 @@
 #include "../../../types/plugin_state.h"
 #include "../../../types/plugin_event.h"
 
+#define INPUT_BUFFER_SIZE (255)
+
 typedef struct {
     char* user_input;
     size_t user_input_length;
@@ -20,8 +22,6 @@ typedef struct {
     void* callback_data;
 } InputTextSceneContext;
 
-#define INPUT_BUFFER_SIZE 255
-
 typedef struct {
     TextInput* text_input;
     View* text_input_view;

+ 0 - 8
ui/scenes/add_new_token/totp_scene_add_new_token.c

@@ -44,10 +44,6 @@ typedef struct {
     FuriString* duration_text;
 } SceneState;
 
-void totp_scene_add_new_token_init(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}
-
 static void on_token_name_user_comitted(InputTextSceneCallbackResult* result) {
     SceneState* scene_state = result->callback_data;
     free(scene_state->token_name);
@@ -354,7 +350,3 @@ void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
     free(plugin_state->current_scene_state);
     plugin_state->current_scene_state = NULL;
 }
-
-void totp_scene_add_new_token_free(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}

+ 0 - 2
ui/scenes/add_new_token/totp_scene_add_new_token.h

@@ -10,11 +10,9 @@ typedef struct {
     uint16_t current_token_index;
 } TokenAddEditSceneContext;
 
-void totp_scene_add_new_token_init(const PluginState* plugin_state);
 void totp_scene_add_new_token_activate(
     PluginState* plugin_state,
     const TokenAddEditSceneContext* context);
 void totp_scene_add_new_token_render(Canvas* const canvas, PluginState* plugin_state);
 bool totp_scene_add_new_token_handle_event(PluginEvent* const event, PluginState* plugin_state);
 void totp_scene_add_new_token_deactivate(PluginState* plugin_state);
-void totp_scene_add_new_token_free(const PluginState* plugin_state);

+ 0 - 8
ui/scenes/app_settings/totp_app_settings.c

@@ -44,10 +44,6 @@ typedef struct {
     Control selected_control;
 } SceneState;
 
-void totp_scene_app_settings_init(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}
-
 void totp_scene_app_settings_activate(
     PluginState* plugin_state,
     const AppSettingsSceneContext* context) {
@@ -332,7 +328,3 @@ void totp_scene_app_settings_deactivate(PluginState* plugin_state) {
     free(plugin_state->current_scene_state);
     plugin_state->current_scene_state = NULL;
 }
-
-void totp_scene_app_settings_free(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}

+ 1 - 3
ui/scenes/app_settings/totp_app_settings.h

@@ -8,7 +8,6 @@ typedef struct {
     uint16_t current_token_index;
 } AppSettingsSceneContext;
 
-void totp_scene_app_settings_init(const PluginState* plugin_state);
 void totp_scene_app_settings_activate(
     PluginState* plugin_state,
     const AppSettingsSceneContext* context);
@@ -16,5 +15,4 @@ void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plu
 bool totp_scene_app_settings_handle_event(
     const PluginEvent* const event,
     PluginState* plugin_state);
-void totp_scene_app_settings_deactivate(PluginState* plugin_state);
-void totp_scene_app_settings_free(const PluginState* plugin_state);
+void totp_scene_app_settings_deactivate(PluginState* plugin_state);

+ 0 - 8
ui/scenes/authenticate/totp_scene_authenticate.c

@@ -18,10 +18,6 @@ typedef struct {
     uint8_t code_length;
 } SceneState;
 
-void totp_scene_authenticate_init(PluginState* plugin_state) {
-    memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE);
-}
-
 void totp_scene_authenticate_activate(PluginState* plugin_state) {
     SceneState* scene_state = malloc(sizeof(SceneState));
     furi_check(scene_state != NULL);
@@ -162,7 +158,3 @@ void totp_scene_authenticate_deactivate(PluginState* plugin_state) {
     free(plugin_state->current_scene_state);
     plugin_state->current_scene_state = NULL;
 }
-
-void totp_scene_authenticate_free(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}

+ 0 - 2
ui/scenes/authenticate/totp_scene_authenticate.h

@@ -4,11 +4,9 @@
 #include "../../../types/plugin_state.h"
 #include "../../../types/plugin_event.h"
 
-void totp_scene_authenticate_init(PluginState* plugin_state);
 void totp_scene_authenticate_activate(PluginState* plugin_state);
 void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_state);
 bool totp_scene_authenticate_handle_event(
     const PluginEvent* const event,
     PluginState* plugin_state);
 void totp_scene_authenticate_deactivate(PluginState* plugin_state);
-void totp_scene_authenticate_free(const PluginState* plugin_state);

+ 4 - 11
ui/scenes/generate_token/totp_scene_generate_token.c

@@ -21,9 +21,9 @@
 #endif
 #include "../../fonts/mode-nine/mode-nine.h"
 
+#define PROGRESS_BAR_MARGIN (3)
+#define PROGRESS_BAR_HEIGHT (4)
 static const char* STEAM_ALGO_ALPHABET = "23456789BCDFGHJKMNPQRTVWXY";
-static const uint8_t PROGRESS_BAR_MARGIN = 3;
-static const uint8_t PROGRESS_BAR_HEIGHT = 4;
 
 typedef struct {
     uint16_t current_token_index;
@@ -177,6 +177,7 @@ static void draw_totp_code(Canvas* const canvas, const SceneState* const scene_s
     uint8_t char_width = modeNine_15ptFontInfo.charInfo[0].width;
     uint8_t total_length = code_length * (char_width + modeNine_15ptFontInfo.spacePixels);
     uint8_t offset_x = (SCREEN_WIDTH - total_length) >> 1;
+    uint8_t offset_x_inc = char_width + modeNine_15ptFontInfo.spacePixels;
     uint8_t offset_y = SCREEN_HEIGHT_CENTER - (modeNine_15ptFontInfo.height >> 1);
     for(uint8_t i = 0; i < code_length; i++) {
         char ch = scene_state->last_code[i];
@@ -189,14 +190,10 @@ static void draw_totp_code(Canvas* const canvas, const SceneState* const scene_s
             modeNine_15ptFontInfo.height,
             &modeNine_15ptFontInfo.data[modeNine_15ptFontInfo.charInfo[char_index].offset]);
 
-        offset_x += char_width + modeNine_15ptFontInfo.spacePixels;
+        offset_x += offset_x_inc;
     }
 }
 
-void totp_scene_generate_token_init(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}
-
 void totp_scene_generate_token_activate(
     PluginState* plugin_state,
     const GenerateTokenSceneContext* context) {
@@ -518,7 +515,3 @@ void totp_scene_generate_token_deactivate(PluginState* plugin_state) {
     free(scene_state);
     plugin_state->current_scene_state = NULL;
 }
-
-void totp_scene_generate_token_free(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}

+ 0 - 2
ui/scenes/generate_token/totp_scene_generate_token.h

@@ -8,7 +8,6 @@ typedef struct {
     uint16_t current_token_index;
 } GenerateTokenSceneContext;
 
-void totp_scene_generate_token_init(const PluginState* plugin_state);
 void totp_scene_generate_token_activate(
     PluginState* plugin_state,
     const GenerateTokenSceneContext* context);
@@ -17,4 +16,3 @@ bool totp_scene_generate_token_handle_event(
     const PluginEvent* const event,
     PluginState* plugin_state);
 void totp_scene_generate_token_deactivate(PluginState* plugin_state);
-void totp_scene_generate_token_free(const PluginState* plugin_state);

+ 0 - 8
ui/scenes/token_menu/totp_scene_token_menu.c

@@ -24,10 +24,6 @@ typedef struct {
     TotpNullable_uint16_t current_token_index;
 } SceneState;
 
-void totp_scene_token_menu_init(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}
-
 void totp_scene_token_menu_activate(
     PluginState* plugin_state,
     const TokenMenuSceneContext* context) {
@@ -204,7 +200,3 @@ void totp_scene_token_menu_deactivate(PluginState* plugin_state) {
     free(plugin_state->current_scene_state);
     plugin_state->current_scene_state = NULL;
 }
-
-void totp_scene_token_menu_free(const PluginState* plugin_state) {
-    UNUSED(plugin_state);
-}

+ 0 - 2
ui/scenes/token_menu/totp_scene_token_menu.h

@@ -8,11 +8,9 @@ typedef struct {
     uint16_t current_token_index;
 } TokenMenuSceneContext;
 
-void totp_scene_token_menu_init(const PluginState* plugin_state);
 void totp_scene_token_menu_activate(
     PluginState* plugin_state,
     const TokenMenuSceneContext* context);
 void totp_scene_token_menu_render(Canvas* const canvas, PluginState* plugin_state);
 bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginState* plugin_state);
 void totp_scene_token_menu_deactivate(PluginState* plugin_state);
-void totp_scene_token_menu_free(const PluginState* plugin_state);

+ 2 - 2
ui/ui_controls.c

@@ -2,8 +2,8 @@
 #include <totp_icons.h>
 #include "constants.h"
 
-#define TEXT_BOX_HEIGHT 13
-#define TEXT_BOX_MARGIN 4
+#define TEXT_BOX_HEIGHT (13)
+#define TEXT_BOX_MARGIN (4)
 
 void ui_control_text_box_render(
     Canvas* const canvas,

+ 1 - 1
workers/bt_type_code/bt_type_code.h

@@ -7,7 +7,7 @@
 #include "../../features_config.h"
 
 #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME
-#define TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN 18
+#define TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN (18)
 #define TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN GAP_MAC_ADDR_SIZE
 #endif