Skip to content

Commit ad56859

Browse files
committed
Fixed issue #6
1 parent 7778892 commit ad56859

File tree

4 files changed

+11
-45
lines changed

4 files changed

+11
-45
lines changed

totp/scenes/generate_token/totp_scene_generate_token.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ void update_totp_params(PluginState* const plugin_state) {
8787
SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
8888

8989
if(scene_state->current_token_index < plugin_state->tokens_count) {
90-
TokenInfo* tokenInfo =
91-
(TokenInfo*)(list_element_at(
92-
plugin_state->tokens_list, scene_state->current_token_index)
93-
->data);
90+
TokenInfo* tokenInfo = list_element_at(plugin_state->tokens_list, scene_state->current_token_index)->data;
9491

9592
scene_state->need_token_update = true;
9693
scene_state->last_code_name = tokenInfo->name;

totp/services/base32/base32.c

+4-33
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// limitations under the License.
1717

1818
#include <string.h>
19+
#include <stdbool.h>
1920

2021
#include "base32.h"
2122

@@ -25,9 +26,11 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
2526
int count = 0;
2627
for(const uint8_t* ptr = encoded; count < bufSize && *ptr; ++ptr) {
2728
uint8_t ch = *ptr;
28-
if(ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == '-') {
29+
bool chIsValid = (ch >= '0' && ch <= '8') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z');
30+
if(!chIsValid) {
2931
continue;
3032
}
33+
3134
buffer <<= 5;
3235

3336
// Deal with commonly mistyped characters
@@ -60,35 +63,3 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
6063
}
6164
return count;
6265
}
63-
64-
int base32_encode(const uint8_t* data, int length, uint8_t* result, int bufSize) {
65-
if(length < 0 || length > (1 << 28)) {
66-
return -1;
67-
}
68-
int count = 0;
69-
if(length > 0) {
70-
int buffer = data[0];
71-
int next = 1;
72-
int bitsLeft = 8;
73-
while(count < bufSize && (bitsLeft > 0 || next < length)) {
74-
if(bitsLeft < 5) {
75-
if(next < length) {
76-
buffer <<= 8;
77-
buffer |= data[next++] & 0xFF;
78-
bitsLeft += 8;
79-
} else {
80-
int pad = 5 - bitsLeft;
81-
buffer <<= pad;
82-
bitsLeft += pad;
83-
}
84-
}
85-
int index = 0x1F & (buffer >> (bitsLeft - 5));
86-
bitsLeft -= 5;
87-
result[count++] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[index];
88-
}
89-
}
90-
if(count < bufSize) {
91-
result[count] = '\000';
92-
}
93-
return count;
94-
}

totp/services/base32/base32.h

-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,3 @@
3131

3232
int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize)
3333
__attribute__((visibility("hidden")));
34-
int base32_encode(const uint8_t* data, int length, uint8_t* result, int bufSize)
35-
__attribute__((visibility("hidden")));

totp/totp_app.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static bool totp_state_init(PluginState* const plugin_state) {
7777
return true;
7878
}
7979

80-
static void dispose_plugin_state(PluginState* plugin_state) {
80+
static void plugin_state_free(PluginState* plugin_state) {
8181
totp_scene_director_deactivate_active_scene(plugin_state);
8282

8383
totp_scene_director_dispose(plugin_state);
@@ -90,7 +90,7 @@ static void dispose_plugin_state(PluginState* plugin_state) {
9090
ListNode* tmp;
9191
while (node != NULL) {
9292
tmp = node->next;
93-
TokenInfo* tokenInfo = (TokenInfo*)node->data;
93+
TokenInfo* tokenInfo = node->data;
9494
token_info_free(tokenInfo);
9595
free(node);
9696
node = tmp;
@@ -108,14 +108,14 @@ int32_t totp_app() {
108108

109109
if (!totp_state_init(plugin_state)) {
110110
FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
111-
dispose_plugin_state(plugin_state);
111+
plugin_state_free(plugin_state);
112112
return 254;
113113
}
114114

115115
ValueMutex state_mutex;
116116
if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
117117
FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
118-
dispose_plugin_state(plugin_state);
118+
plugin_state_free(plugin_state);
119119
return 255;
120120
}
121121

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

137-
PluginState* plugin_state = (PluginState*)acquire_mutex_block(&state_mutex);
137+
PluginState* plugin_state = acquire_mutex_block(&state_mutex);
138138

139139
if(event_status == FuriStatusOk) {
140140
if (event.type == EventTypeKey) {
@@ -155,6 +155,6 @@ int32_t totp_app() {
155155
view_port_free(view_port);
156156
furi_message_queue_free(event_queue);
157157
delete_mutex(&state_mutex);
158-
dispose_plugin_state(plugin_state);
158+
plugin_state_free(plugin_state);
159159
return 0;
160160
}

0 commit comments

Comments
 (0)