Skip to content

Commit

Permalink
Fixed issue #6
Browse files Browse the repository at this point in the history
  • Loading branch information
akopachov committed Oct 21, 2022
1 parent a55ac88 commit 2674ab5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 45 deletions.
5 changes: 1 addition & 4 deletions scenes/generate_token/totp_scene_generate_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ void update_totp_params(PluginState* const plugin_state) {
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;

if(scene_state->current_token_index < plugin_state->tokens_count) {
TokenInfo* tokenInfo =
(TokenInfo*)(list_element_at(
plugin_state->tokens_list, scene_state->current_token_index)
->data);
TokenInfo* tokenInfo = list_element_at(plugin_state->tokens_list, scene_state->current_token_index)->data;

scene_state->need_token_update = true;
scene_state->last_code_name = tokenInfo->name;
Expand Down
37 changes: 4 additions & 33 deletions services/base32/base32.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

#include <string.h>
#include <stdbool.h>

#include "base32.h"

Expand All @@ -25,9 +26,11 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
int count = 0;
for(const uint8_t* ptr = encoded; count < bufSize && *ptr; ++ptr) {
uint8_t ch = *ptr;
if(ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-') {
bool chIsValid = (ch >= '0' && ch <= '8') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
if(!chIsValid) {
continue;
}

buffer <<= 5;

// Deal with commonly mistyped characters
Expand Down Expand Up @@ -60,35 +63,3 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
}
return count;
}

int base32_encode(const uint8_t* data, int length, uint8_t* result, int bufSize) {
if(length < 0 || length > (1 << 28)) {
return -1;
}
int count = 0;
if(length > 0) {
int buffer = data[0];
int next = 1;
int bitsLeft = 8;
while(count < bufSize && (bitsLeft > 0 || next < length)) {
if(bitsLeft < 5) {
if(next < length) {
buffer <<= 8;
buffer |= data[next++] & 0xFF;
bitsLeft += 8;
} else {
int pad = 5 - bitsLeft;
buffer <<= pad;
bitsLeft += pad;
}
}
int index = 0x1F & (buffer >> (bitsLeft - 5));
bitsLeft -= 5;
result[count++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[index];
}
}
if(count < bufSize) {
result[count] = '\000';
}
return count;
}
2 changes: 0 additions & 2 deletions services/base32/base32.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@

int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize)
__attribute__((visibility("hidden")));
int base32_encode(const uint8_t* data, int length, uint8_t* result, int bufSize)
__attribute__((visibility("hidden")));
12 changes: 6 additions & 6 deletions totp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static bool totp_state_init(PluginState* const plugin_state) {
return true;
}

static void dispose_plugin_state(PluginState* plugin_state) {
static void plugin_state_free(PluginState* plugin_state) {
totp_scene_director_deactivate_active_scene(plugin_state);

totp_scene_director_dispose(plugin_state);
Expand All @@ -90,7 +90,7 @@ static void dispose_plugin_state(PluginState* plugin_state) {
ListNode* tmp;
while (node != NULL) {
tmp = node->next;
TokenInfo* tokenInfo = (TokenInfo*)node->data;
TokenInfo* tokenInfo = node->data;
token_info_free(tokenInfo);
free(node);
node = tmp;
Expand All @@ -108,14 +108,14 @@ int32_t totp_app() {

if (!totp_state_init(plugin_state)) {
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
dispose_plugin_state(plugin_state);
plugin_state_free(plugin_state);
return 254;
}

ValueMutex state_mutex;
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
dispose_plugin_state(plugin_state);
plugin_state_free(plugin_state);
return 255;
}

Expand All @@ -134,7 +134,7 @@ int32_t totp_app() {
if (plugin_state->changing_scene) continue;
FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);

PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex);
PluginState* plugin_state = acquire_mutex_block(&state_mutex);

if(event_status == FuriStatusOk) {
if (event.type == EventTypeKey) {
Expand All @@ -155,6 +155,6 @@ int32_t totp_app() {
view_port_free(view_port);
furi_message_queue_free(event_queue);
delete_mutex(&state_mutex);
dispose_plugin_state(plugin_state);
plugin_state_free(plugin_state);
return 0;
}

0 comments on commit 2674ab5

Please sign in to comment.