Skip to content

Commit

Permalink
Fixed SONAR issues (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Oct 28, 2022
1 parent 29eae25 commit fef9a4d
Show file tree
Hide file tree
Showing 21 changed files with 59 additions and 53 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
![contributions - welcome](https://img.shields.io/badge/contributions-welcome-blue)
[![Discord server](https://img.shields.io/discord/937479784148115456)](https://discord.com/channels/937479784148115456)

---

[![SonarCloud](https://sonarcloud.io/images/project_badges/sonarcloud-white.svg)](https://sonarcloud.io/summary/new_code?id=akopachov_flipper-zero_authenticator)

---

![Screenshot](docs/assets/screenshot_1.png)

## Description
Expand Down
6 changes: 3 additions & 3 deletions totp/scenes/add_new_token/totp_scene_add_new_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ typedef struct {
InputTextSceneState* input_state;
uint32_t input_started_at;
int16_t current_token_index;
int32_t screen_y_offset;
int16_t screen_y_offset;
TokenHashAlgo algo;
TokenDigitsCount digits_count;
} SceneState;

void totp_scene_add_new_token_init(PluginState* plugin_state) {
void totp_scene_add_new_token_init(const PluginState* plugin_state) {
UNUSED(plugin_state);
}

Expand Down Expand Up @@ -311,6 +311,6 @@ void totp_scene_add_new_token_deactivate(PluginState* plugin_state) {
plugin_state->current_scene_state = NULL;
}

void totp_scene_add_new_token_free(PluginState* plugin_state) {
void totp_scene_add_new_token_free(const PluginState* plugin_state) {
UNUSED(plugin_state);
}
4 changes: 2 additions & 2 deletions totp/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,11 @@ typedef struct {
uint8_t current_token_index;
} TokenAddEditSceneContext;

void totp_scene_add_new_token_init(PluginState* plugin_state);
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(PluginState* plugin_state);
void totp_scene_add_new_token_free(const PluginState* plugin_state);
8 changes: 4 additions & 4 deletions totp/scenes/app_settings/totp_app_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ typedef struct {
Control selected_control;
} SceneState;

void totp_scene_app_settings_init(PluginState* plugin_state) {
void totp_scene_app_settings_init(const PluginState* plugin_state) {
UNUSED(plugin_state);
}

Expand Down Expand Up @@ -53,7 +53,7 @@ static void two_digit_to_str(int8_t num, char* str) {
}

void totp_scene_app_settings_render(Canvas* const canvas, PluginState* plugin_state) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
const SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;

canvas_set_font(canvas, FontPrimary);
canvas_draw_str_aligned(canvas, 0, 0, AlignLeft, AlignTop, "Timezone offset");
Expand Down Expand Up @@ -90,7 +90,7 @@ void totp_scene_app_settings_render(Canvas* const canvas, PluginState* plugin_st
scene_state->selected_control == ConfirmButton);
}

bool totp_scene_app_settings_handle_event(PluginEvent* const event, PluginState* plugin_state) {
bool totp_scene_app_settings_handle_event(const PluginEvent* const event, PluginState* plugin_state) {
if(event->type == EventTypeKey) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
if(event->input.type == InputTypePress) {
Expand Down Expand Up @@ -171,6 +171,6 @@ void totp_scene_app_settings_deactivate(PluginState* plugin_state) {
plugin_state->current_scene_state = NULL;
}

void totp_scene_app_settings_free(PluginState* plugin_state) {
void totp_scene_app_settings_free(const PluginState* plugin_state) {
UNUSED(plugin_state);
}
6 changes: 3 additions & 3 deletions totp/scenes/app_settings/totp_app_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ typedef struct {
uint8_t current_token_index;
} AppSettingsSceneContext;

void totp_scene_app_settings_init(PluginState* plugin_state);
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, PluginState* plugin_state);
bool totp_scene_app_settings_handle_event(PluginEvent* const event, 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(PluginState* plugin_state);
void totp_scene_app_settings_free(const PluginState* plugin_state);
6 changes: 3 additions & 3 deletions totp/scenes/authenticate/totp_scene_authenticate.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void totp_scene_authenticate_activate(PluginState* plugin_state) {
}

void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_state) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
const SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;

int v_shift = 0;
if(scene_state->code_length > 0) {
Expand Down Expand Up @@ -73,7 +73,7 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st
}
}

bool totp_scene_authenticate_handle_event(PluginEvent* const event, PluginState* plugin_state) {
bool totp_scene_authenticate_handle_event(const PluginEvent* const event, PluginState* plugin_state) {
if(event->type == EventTypeKey) {
if(event->input.type == InputTypeLong && event->input.key == InputKeyBack) {
return false;
Expand Down Expand Up @@ -156,6 +156,6 @@ void totp_scene_authenticate_deactivate(PluginState* plugin_state) {
plugin_state->current_scene_state = NULL;
}

void totp_scene_authenticate_free(PluginState* plugin_state) {
void totp_scene_authenticate_free(const PluginState* plugin_state) {
UNUSED(plugin_state);
}
4 changes: 2 additions & 2 deletions totp/scenes/authenticate/totp_scene_authenticate.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
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(PluginEvent* const event, 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(PluginState* plugin_state);
void totp_scene_authenticate_free(const PluginState* plugin_state);
8 changes: 4 additions & 4 deletions totp/scenes/token_menu/totp_scene_token_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ typedef struct {
int16_t current_token_index;
} SceneState;

void totp_scene_token_menu_init(PluginState* plugin_state) {
void totp_scene_token_menu_init(const PluginState* plugin_state) {
UNUSED(plugin_state);
}

Expand All @@ -38,7 +38,7 @@ void totp_scene_token_menu_activate(
}

void totp_scene_token_menu_render(Canvas* const canvas, PluginState* plugin_state) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
const SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
if(scene_state->current_token_index < 0) {
ui_control_button_render(
canvas,
Expand Down Expand Up @@ -84,7 +84,7 @@ void totp_scene_token_menu_render(Canvas* const canvas, PluginState* plugin_stat
}
}

bool totp_scene_token_menu_handle_event(PluginEvent* const event, PluginState* plugin_state) {
bool totp_scene_token_menu_handle_event(const PluginEvent* const event, PluginState* plugin_state) {
if(event->type == EventTypeKey) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
if(event->input.type == InputTypePress) {
Expand Down Expand Up @@ -192,6 +192,6 @@ void totp_scene_token_menu_deactivate(PluginState* plugin_state) {
plugin_state->current_scene_state = NULL;
}

void totp_scene_token_menu_free(PluginState* plugin_state) {
void totp_scene_token_menu_free(const PluginState* plugin_state) {
UNUSED(plugin_state);
}
6 changes: 3 additions & 3 deletions totp/scenes/token_menu/totp_scene_token_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ typedef struct {
uint8_t current_token_index;
} TokenMenuSceneContext;

void totp_scene_token_menu_init(PluginState* plugin_state);
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(PluginEvent* const event, 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(PluginState* plugin_state);
void totp_scene_token_menu_free(const PluginState* plugin_state);
2 changes: 1 addition & 1 deletion totp/services/cli/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "commands/timezone/timezone.h"
#include "commands/help/help.h"

static void totp_cli_print_unknown_command(FuriString* unknown_command) {
static void totp_cli_print_unknown_command(const FuriString* unknown_command) {
TOTP_CLI_PRINTF(
"Command \"%s\" is unknown. Use \"" TOTP_CLI_COMMAND_HELP
"\" command to get list of available commands.",
Expand Down
2 changes: 1 addition & 1 deletion totp/services/cli/cli_helpers.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "cli_helpers.h"
#include <cli/cli.h>

bool totp_cli_ensure_authenticated(PluginState* plugin_state, Cli* cli) {
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli) {
if(plugin_state->current_scene == TotpSceneAuthentication) {
TOTP_CLI_PRINTF("Pleases enter PIN on your flipper device\r\n");

Expand Down
2 changes: 1 addition & 1 deletion totp/services/cli/cli_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
TOTP_CLI_PRINTF( \
"Invalid command arguments. use \"help\" command to get list of available commands")

bool totp_cli_ensure_authenticated(PluginState* plugin_state, Cli* cli);
bool totp_cli_ensure_authenticated(const PluginState* plugin_state, Cli* cli);
4 changes: 2 additions & 2 deletions totp/services/cli/commands/add/add.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#define TOTP_CLI_COMMAND_ADD_ARG_DIGITS_PREFIX "-d"
#define TOTP_CLI_COMMAND_ADD_ARG_UNSECURE_PREFIX "-u"

static bool token_info_set_digits_from_str(TokenInfo* token_info, FuriString* str) {
static bool token_info_set_digits_from_str(TokenInfo* token_info, const FuriString* str) {
switch(furi_string_get_char(str, 0)) {
case '6':
token_info->digits = TOTP_6_DIGITS;
Expand All @@ -27,7 +27,7 @@ static bool token_info_set_digits_from_str(TokenInfo* token_info, FuriString* st
return false;
}

static bool token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str) {
static bool token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) {
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
token_info->algo = SHA1;
return true;
Expand Down
14 changes: 7 additions & 7 deletions totp/services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf"
#define CONFIG_FILE_BACKUP_PATH CONFIG_FILE_PATH ".backup"

static uint8_t token_info_get_digits_as_int(TokenInfo* token_info) {
static uint8_t token_info_get_digits_as_int(const TokenInfo* token_info) {
switch(token_info->digits) {
case TOTP_6_DIGITS:
return 6;
Expand All @@ -32,7 +32,7 @@ static void token_info_set_digits_from_int(TokenInfo* token_info, uint8_t digits
}
}

static char* token_info_get_algo_as_cstr(TokenInfo* token_info) {
static char* token_info_get_algo_as_cstr(const TokenInfo* token_info) {
switch(token_info->algo) {
case SHA1:
return TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME;
Expand All @@ -45,7 +45,7 @@ static char* token_info_get_algo_as_cstr(TokenInfo* token_info) {
return NULL;
}

static void token_info_set_algo_from_str(TokenInfo* token_info, FuriString* str) {
static void token_info_set_algo_from_str(TokenInfo* token_info, const FuriString* str) {
if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA1_NAME) == 0) {
token_info->algo = SHA1;
} else if(furi_string_cmpi_str(str, TOTP_CONFIG_TOKEN_ALGO_SHA256_NAME) == 0) {
Expand Down Expand Up @@ -152,7 +152,7 @@ FlipperFormat* totp_open_config_file(Storage* storage) {
return fff_data_file;
}

void totp_config_file_save_new_token_i(FlipperFormat* file, TokenInfo* token_info) {
void totp_config_file_save_new_token_i(FlipperFormat* file, const TokenInfo* token_info) {
flipper_format_seek_to_end(file);
flipper_format_write_string_cstr(file, TOTP_CONFIG_KEY_TOKEN_NAME, token_info->name);
bool token_is_valid = token_info->token != NULL && token_info->token_length > 0;
Expand All @@ -170,7 +170,7 @@ void totp_config_file_save_new_token_i(FlipperFormat* file, TokenInfo* token_inf
flipper_format_write_uint32(file, TOTP_CONFIG_KEY_TOKEN_DIGITS, &digits_count_as_uint32, 1);
}

void totp_config_file_save_new_token(TokenInfo* token_info) {
void totp_config_file_save_new_token(const TokenInfo* token_info) {
Storage* cfg_storage = totp_open_storage();
FlipperFormat* file = totp_open_config_file(cfg_storage);

Expand All @@ -190,7 +190,7 @@ void totp_config_file_update_timezone_offset(float new_timezone_offset) {
totp_close_storage();
}

void totp_full_save_config_file(PluginState* const plugin_state) {
void totp_full_save_config_file(const PluginState* const plugin_state) {
Storage* storage = totp_open_storage();
FlipperFormat* fff_data_file = flipper_format_file_alloc(storage);

Expand All @@ -209,7 +209,7 @@ void totp_full_save_config_file(PluginState* const plugin_state) {
flipper_format_write_bool(fff_data_file, TOTP_CONFIG_KEY_PINSET, &plugin_state->pin_set, 1);
ListNode* node = plugin_state->tokens_list;
while(node != NULL) {
TokenInfo* token_info = node->data;
const TokenInfo* token_info = node->data;
totp_config_file_save_new_token_i(fff_data_file, token_info);
node = node->next;
}
Expand Down
4 changes: 2 additions & 2 deletions totp/services/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Storage* totp_open_storage();
void totp_close_storage();
FlipperFormat* totp_open_config_file(Storage* storage);
void totp_close_config_file(FlipperFormat* file);
void totp_full_save_config_file(PluginState* const plugin_state);
void totp_full_save_config_file(const PluginState* const plugin_state);
void totp_config_file_load_base(PluginState* const plugin_state);
TokenLoadingResult totp_config_file_load_tokens(PluginState* const plugin_state);
void totp_config_file_save_new_token(TokenInfo* token_info);
void totp_config_file_save_new_token(const TokenInfo* token_info);
void totp_config_file_update_timezone_offset(float new_timezone_offset);
4 changes: 2 additions & 2 deletions totp/services/crypto/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint8_t* totp_crypto_decrypt(
return decrypted_data;
}

void totp_crypto_seed_iv(PluginState* plugin_state, uint8_t* pin, uint8_t pin_length) {
void totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length) {
if(plugin_state->crypto_verify_data == NULL) {
FURI_LOG_D(LOGGING_TAG, "Generating new IV");
furi_hal_random_fill_buf(&plugin_state->base_iv[0], TOTP_IV_SIZE);
Expand Down Expand Up @@ -120,7 +120,7 @@ void totp_crypto_seed_iv(PluginState* plugin_state, uint8_t* pin, uint8_t pin_le

bool totp_crypto_verify_key(const PluginState* plugin_state) {
size_t decrypted_key_length;
uint8_t* decrypted_key = totp_crypto_decrypt(
const uint8_t* decrypted_key = totp_crypto_decrypt(
plugin_state->crypto_verify_data,
plugin_state->crypto_verify_data_length,
&plugin_state->iv[0],
Expand Down
2 changes: 1 addition & 1 deletion totp/services/crypto/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ uint8_t* totp_crypto_decrypt(
const size_t encrypted_data_length,
const uint8_t* iv,
size_t* decrypted_data_length);
void totp_crypto_seed_iv(PluginState* plugin_state, uint8_t* pin, uint8_t pin_length);
void totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length);
bool totp_crypto_verify_key(const PluginState* plugin_state);
2 changes: 1 addition & 1 deletion totp/services/totp/totp.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ uint32_t otp_generate(

uint64_t input_swapped = swap_uint64(input);

int hmac_len = (*(algo))(plain_secret, plain_secret_length, (uint8_t*)&input_swapped, 8, hmac);
int hmac_len = (*algo)(plain_secret, plain_secret_length, (uint8_t*)&input_swapped, 8, hmac);
if(hmac_len == 0) {
free(hmac);
return OTP_ERROR;
Expand Down
6 changes: 3 additions & 3 deletions totp/services/ui/ui_controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define TEXT_BOX_HEIGHT 13
#define TEXT_BOX_MARGIN 4

void ui_control_text_box_render(Canvas* const canvas, int8_t y, char* text, bool is_selected) {
void ui_control_text_box_render(Canvas* const canvas, int16_t y, const char* text, bool is_selected) {
if(y < -TEXT_BOX_HEIGHT) {
return;
}
Expand Down Expand Up @@ -44,7 +44,7 @@ void ui_control_select_render(
int16_t x,
int16_t y,
uint8_t width,
char* text,
const char* text,
bool is_selected) {
if(y < -TEXT_BOX_HEIGHT) {
return;
Expand Down Expand Up @@ -99,7 +99,7 @@ void ui_control_button_render(
int16_t y,
uint8_t width,
uint8_t height,
char* text,
const char* text,
bool is_selected) {
if(y < -height) {
return;
Expand Down
6 changes: 3 additions & 3 deletions totp/services/ui/ui_controls.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#include <inttypes.h>
#include <gui/gui.h>

void ui_control_text_box_render(Canvas* const canvas, int8_t y, char* text, bool is_selected);
void ui_control_text_box_render(Canvas* const canvas, int16_t y, const char* text, bool is_selected);
void ui_control_button_render(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t width,
uint8_t height,
char* text,
const char* text,
bool is_selected);
void ui_control_select_render(
Canvas* const canvas,
int16_t x,
int16_t y,
uint8_t width,
char* text,
const char* text,
bool is_selected);
Loading

0 comments on commit fef9a4d

Please sign in to comment.