Skip to content

Commit

Permalink
Refactoring. Dropping useless methods #120 (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Apr 7, 2023
1 parent b4e434b commit 5aff2f0
Show file tree
Hide file tree
Showing 27 changed files with 40 additions and 110 deletions.
6 changes: 3 additions & 3 deletions features_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/base32/base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#pragma once

#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/base64/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 1 addition & 1 deletion services/config/constants.h
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 3 additions & 3 deletions services/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions services/hmac/hmac_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion types/plugin_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions types/token_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions ui/constants.h
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions ui/fonts/mode-nine/mode-nine.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "mode-nine.h"
#include <stdint.h>

/* GENERATED BY https://github.com/pavius/the-dot-factory */

Expand Down
1 change: 0 additions & 1 deletion ui/fonts/mode-nine/mode-nine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 0 additions & 16 deletions ui/scene_director.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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) {
Expand Down
12 changes: 0 additions & 12 deletions ui/scene_director.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,13 @@ 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
* @param plugin_state application 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
Expand Down
4 changes: 2 additions & 2 deletions ui/scenes/add_new_token/totp_input_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,8 +22,6 @@ typedef struct {
void* callback_data;
} InputTextSceneContext;

#define INPUT_BUFFER_SIZE 255

typedef struct {
TextInput* text_input;
View* text_input_view;
Expand Down
8 changes: 0 additions & 8 deletions ui/scenes/add_new_token/totp_scene_add_new_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
2 changes: 0 additions & 2 deletions ui/scenes/add_new_token/totp_scene_add_new_token.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
8 changes: 0 additions & 8 deletions ui/scenes/app_settings/totp_app_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
4 changes: 1 addition & 3 deletions ui/scenes/app_settings/totp_app_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ 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);
void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state);
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);
8 changes: 0 additions & 8 deletions ui/scenes/authenticate/totp_scene_authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
2 changes: 0 additions & 2 deletions ui/scenes/authenticate/totp_scene_authenticate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
15 changes: 4 additions & 11 deletions ui/scenes/generate_token/totp_scene_generate_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
}
Loading

0 comments on commit 5aff2f0

Please sign in to comment.