alex.kopachov il y a 3 ans
Parent
commit
2674ab5ea6

+ 1 - 4
scenes/generate_token/totp_scene_generate_token.c

@@ -87,10 +87,7 @@ void update_totp_params(PluginState* const plugin_state) {
     SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
     SceneState* scene_state = (SceneState*)plugin_state->current_scene_state;
 
 
     if(scene_state->current_token_index < plugin_state->tokens_count) {
     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->need_token_update = true;
         scene_state->last_code_name = tokenInfo->name;
         scene_state->last_code_name = tokenInfo->name;

+ 4 - 33
services/base32/base32.c

@@ -16,6 +16,7 @@
 // limitations under the License.
 // limitations under the License.
 
 
 #include <string.h>
 #include <string.h>
+#include <stdbool.h>
 
 
 #include "base32.h"
 #include "base32.h"
 
 
@@ -25,9 +26,11 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
     int count = 0;
     int count = 0;
     for(const uint8_t* ptr = encoded; count < bufSize && *ptr; ++ptr) {
     for(const uint8_t* ptr = encoded; count < bufSize && *ptr; ++ptr) {
         uint8_t ch = *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;
             continue;
         }
         }
+
         buffer <<= 5;
         buffer <<= 5;
 
 
         // Deal with commonly mistyped characters
         // Deal with commonly mistyped characters
@@ -60,35 +63,3 @@ int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize) {
     }
     }
     return count;
     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;
-}

+ 0 - 2
services/base32/base32.h

@@ -31,5 +31,3 @@
 
 
 int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize)
 int base32_decode(const uint8_t* encoded, uint8_t* result, int bufSize)
     __attribute__((visibility("hidden")));
     __attribute__((visibility("hidden")));
-int base32_encode(const uint8_t* data, int length, uint8_t* result, int bufSize)
-    __attribute__((visibility("hidden")));

+ 6 - 6
totp_app.c

@@ -77,7 +77,7 @@ static bool totp_state_init(PluginState* const plugin_state) {
     return true;
     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_deactivate_active_scene(plugin_state);
 
 
     totp_scene_director_dispose(plugin_state);
     totp_scene_director_dispose(plugin_state);
@@ -90,7 +90,7 @@ static void dispose_plugin_state(PluginState* plugin_state) {
     ListNode* tmp;
     ListNode* tmp;
     while (node != NULL) {
     while (node != NULL) {
         tmp = node->next;
         tmp = node->next;
-        TokenInfo* tokenInfo = (TokenInfo*)node->data;
+        TokenInfo* tokenInfo = node->data;
         token_info_free(tokenInfo);
         token_info_free(tokenInfo);
         free(node);
         free(node);
         node = tmp;
         node = tmp;
@@ -108,14 +108,14 @@ int32_t totp_app() {
 
 
     if (!totp_state_init(plugin_state)) {
     if (!totp_state_init(plugin_state)) {
         FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
         FURI_LOG_E(LOGGING_TAG, "App state initialization failed\r\n");
-        dispose_plugin_state(plugin_state);
+        plugin_state_free(plugin_state);
         return 254;
         return 254;
     }
     }
 
 
     ValueMutex state_mutex;
     ValueMutex state_mutex;
     if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
     if(!init_mutex(&state_mutex, plugin_state, sizeof(PluginState))) {
         FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
         FURI_LOG_E(LOGGING_TAG, "Cannot create mutex\r\n");
-        dispose_plugin_state(plugin_state);
+        plugin_state_free(plugin_state);
         return 255;
         return 255;
     }
     }
 
 
@@ -134,7 +134,7 @@ int32_t totp_app() {
         if (plugin_state->changing_scene) continue;
         if (plugin_state->changing_scene) continue;
         FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100);
         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_status == FuriStatusOk) {
             if (event.type == EventTypeKey) {
             if (event.type == EventTypeKey) {
@@ -155,6 +155,6 @@ int32_t totp_app() {
     view_port_free(view_port);
     view_port_free(view_port);
     furi_message_queue_free(event_queue);
     furi_message_queue_free(event_queue);
     delete_mutex(&state_mutex);
     delete_mutex(&state_mutex);
-    dispose_plugin_state(plugin_state);
+    plugin_state_free(plugin_state);
     return 0;
     return 0;
 }
 }