Skip to content

Commit

Permalink
Refactoring (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov authored Apr 12, 2023
1 parent 0a9cc9e commit 7b34241
Show file tree
Hide file tree
Showing 22 changed files with 380 additions and 214 deletions.
2 changes: 0 additions & 2 deletions application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ App(
"storage",
"input",
"notification",
#ifdef TOTP_BADBT_TYPE_ENABLED
"bt"
#endif
],
stack_size=2 * 1024,
order=20,
Expand Down
2 changes: 1 addition & 1 deletion cli/commands/reset/reset.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "reset.h"

#include <stdlib.h>
#include <furi/furi.h>
#include <furi/core/string.h>
#include "../../cli_helpers.h"
#include "../../../services/config/config.h"

Expand Down
7 changes: 6 additions & 1 deletion features_config.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// Include Bluetooth token input automation
#ifndef TOTP_NO_BADBT_TYPE
#define TOTP_BADBT_TYPE_ENABLED
#endif

// Include token input automation icons on the main screen
#ifndef TOTP_NO_AUTOMATION_ICONS
#define TOTP_AUTOMATION_ICONS_ENABLED
#endif

// List of compatible firmwares
#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
// Target firmware to build for.
#ifndef TOTP_TARGET_FIRMWARE
// Defaulting to Xtreme if not previously defined
#define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_XTREME
#endif
3 changes: 3 additions & 0 deletions lib/polyfills/strnlen.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#pragma once
#pragma weak strnlen

#include <stddef.h>

size_t strnlen(const char* s, size_t maxlen);
2 changes: 1 addition & 1 deletion services/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static char* totp_config_file_backup_i(Storage* storage) {
}

if(backup_file_exists ||
!storage_common_copy(storage, CONFIG_FILE_PATH, backup_path) == FSE_OK) {
storage_common_copy(storage, CONFIG_FILE_PATH, backup_path) != FSE_OK) {
FURI_LOG_E(LOGGING_TAG, "Unable to take a backup");
free(backup_path);
return NULL;
Expand Down
1 change: 0 additions & 1 deletion services/config/config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include <flipper_format/flipper_format.h>
#include <furi.h>
#include "../../types/plugin_state.h"
#include "../../types/token_info.h"
#include "constants.h"
Expand Down
5 changes: 3 additions & 2 deletions services/crypto/crypto.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "crypto.h"
#include <furi.h>
#include <furi_hal.h>
#include <furi_hal_crypto.h>
#include <furi_hal_random.h>
#include <furi_hal_version.h>
#include "../config/config.h"
#include "../../types/common.h"
#include "memset_s.h"
Expand Down
4 changes: 1 addition & 3 deletions services/totp/totp.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include "totp.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <timezone_utils.h>
#include "../hmac/hmac_sha1.h"
#include "../hmac/hmac_sha256.h"
#include "../hmac/hmac_sha512.h"
#include "../hmac/byteswap.h"
#include "../../lib/timezone_utils/timezone_utils.h"

#define HMAC_MAX_RESULT_SIZE HMAC_SHA512_RESULT_SIZE

Expand Down
7 changes: 0 additions & 7 deletions totp_app.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include <furi.h>
#include <furi_hal.h>
#include <gui/gui.h>
#include <input/input.h>
#include <dialogs/dialogs.h>
#include <stdlib.h>
#include <flipper_format/flipper_format.h>
#include <notification/notification.h>
#include <notification/notification_messages.h>
#include <dolphin/dolphin.h>
Expand Down Expand Up @@ -105,10 +102,6 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) {
}

plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal);
if(plugin_state->mutex == NULL) {
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
return false;
}

#ifdef TOTP_BADBT_TYPE_ENABLED
if(plugin_state->automation_method & AutomationMethodBadBt) {
Expand Down
2 changes: 0 additions & 2 deletions types/token_info.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "token_info.h"
#include <furi_hal.h>
#include <base32.h>
#include <base64.h>
#include <memset_s.h>
#include <strnlen.h>
#include "common.h"
#include "../services/crypto/crypto.h"

Expand Down
2 changes: 1 addition & 1 deletion types/token_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <inttypes.h>
#include <stdbool.h>
#include <furi/furi.h>
#include <furi/core/string.h>

#define TOTP_TOKEN_DURATION_DEFAULT (30)

Expand Down
1 change: 0 additions & 1 deletion ui/scenes/add_new_token/totp_input_text.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "totp_input_text.h"
#include <gui/view_i.h>
#include "../../../lib/polyfills/strnlen.h"

void view_draw(View* view, Canvas* canvas) {
furi_assert(view);
Expand Down
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
@@ -1,8 +1,6 @@
#pragma once

#include <gui/gui.h>
#include <furi.h>
#include <furi_hal.h>
#include "../../../types/plugin_state.h"
#include "../../../types/plugin_event.h"

Expand Down
Loading

0 comments on commit 7b34241

Please sign in to comment.