Skip to content

Commit cb8a2e0

Browse files
committed
Fixes for various apps. swd_probe: untested
1 parent 5a4654d commit cb8a2e0

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

passgen.c

+12-10
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
#include <notification/notification_messages.h>
66
#include <stdlib.h>
77
#include <passgen_icons.h>
8+
#include <core/string.h>
89

910
#define PASSGEN_MAX_LENGTH 16
10-
#define PASSGEN_CHARACTERS_LENGTH (26 * 4)
1111

1212
#define PASSGEN_DIGITS "0123456789"
1313
#define PASSGEN_LETTERS_LOW "abcdefghijklmnopqrstuvwxyz"
1414
#define PASSGEN_LETTERS_UP "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15-
#define PASSGEN_SPECIAL "!#$%^&*.-_"
15+
#define PASSGEN_SPECIAL "!#$%%^&*.-_"
1616

1717
typedef enum PassGen_Alphabet {
1818
Digits = 1,
@@ -45,7 +45,8 @@ typedef struct {
4545
FuriMutex** mutex;
4646
NotificationApp* notify;
4747
char password[PASSGEN_MAX_LENGTH + 1];
48-
char alphabet[PASSGEN_CHARACTERS_LENGTH + 1];
48+
// char alphabet[PASSGEN_CHARACTERS_LENGTH + 1];
49+
FuriString* alphabet;
4950
int length;
5051
int level;
5152
} PassGen;
@@ -57,6 +58,7 @@ void state_free(PassGen* app) {
5758
furi_message_queue_free(app->input_queue);
5859
furi_mutex_free(app->mutex);
5960
furi_record_close(RECORD_NOTIFICATION);
61+
furi_string_free(app->alphabet);
6062
free(app);
6163
}
6264

@@ -98,17 +100,17 @@ static void render_callback(Canvas* canvas, void* ctx) {
98100

99101
void build_alphabet(PassGen* app) {
100102
PassGen_Alphabet mode = AlphabetLevels[app->level];
101-
app->alphabet[0] = '\0';
102-
if((mode & Digits) != 0) strcat(app->alphabet, PASSGEN_DIGITS);
103-
if((mode & Lowercase) != 0) strcat(app->alphabet, PASSGEN_LETTERS_LOW);
104-
if((mode & Uppercase) != 0) strcat(app->alphabet, PASSGEN_LETTERS_UP);
105-
if((mode & Special) != 0) strcat(app->alphabet, PASSGEN_SPECIAL);
103+
if((mode & Digits) != 0) furi_string_cat(app->alphabet, PASSGEN_DIGITS);
104+
if((mode & Lowercase) != 0) furi_string_cat(app->alphabet, PASSGEN_LETTERS_LOW);
105+
if((mode & Uppercase) != 0) furi_string_cat(app->alphabet, PASSGEN_LETTERS_UP);
106+
if((mode & Special) != 0) furi_string_cat(app->alphabet, PASSGEN_SPECIAL);
106107
}
107108

108109
PassGen* state_init() {
109110
PassGen* app = malloc(sizeof(PassGen));
110111
app->length = 8;
111112
app->level = 2;
113+
app->alphabet = furi_string_alloc();
112114
build_alphabet(app);
113115
app->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
114116
app->view_port = view_port_alloc();
@@ -124,10 +126,10 @@ PassGen* state_init() {
124126
}
125127

126128
void generate(PassGen* app) {
127-
int hi = strlen(app->alphabet);
129+
int hi = furi_string_size(app->alphabet);
128130
for(int i = 0; i < app->length; i++) {
129131
int x = rand() % hi;
130-
app->password[i] = app->alphabet[x];
132+
app->password[i] = furi_string_get_char(app->alphabet, x);
131133
}
132134
app->password[app->length] = '\0';
133135
}

0 commit comments

Comments
 (0)