1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-17 20:08:12 +00:00

feat(storage): return enum values instead of strings, so that they are translatable

This commit is contained in:
matejcik 2024-03-15 11:53:43 +01:00 committed by matejcik
parent 0fa9860cf5
commit f60cc75c7c
4 changed files with 22 additions and 17 deletions

View File

@ -137,18 +137,12 @@ const uint8_t WIPE_CODE_EMPTY[] = {0, 0, 0, 0};
// The uint32 representation of an empty wipe code used in storage version 2.
#define V2_WIPE_CODE_EMPTY 0
// TODO: handle translation
const char *const VERIFYING_PIN_MSG = "Verifying PIN";
const char *const PROCESSING_MSG = "Processing";
const char *const STARTING_MSG = "Starting up";
const char *const WRONG_PIN_MSG = "Wrong PIN";
static secbool initialized = secfalse;
static secbool unlocked = secfalse;
static PIN_UI_WAIT_CALLBACK ui_callback = NULL;
static uint32_t ui_total = 0;
static uint32_t ui_rem = 0;
static const char *ui_message = NULL;
static enum storage_ui_message_t ui_message = NO_MSG;
static uint8_t cached_keys[KEYS_SIZE] = {0};
static uint8_t *const cached_dek = cached_keys;
static uint8_t *const cached_sak = cached_keys + DEK_SIZE;
@ -986,7 +980,7 @@ secbool storage_unlock(const uint8_t *pin, size_t pin_len,
ui_total = PIN_DERIVE_MS;
ui_rem = ui_total;
if (pin_len == 0) {
if (ui_message == NULL) {
if (ui_message == NO_MSG) {
ui_message = STARTING_MSG;
} else {
ui_message = PROCESSING_MSG;

View File

@ -53,8 +53,16 @@ extern const uint8_t *PIN_EMPTY;
#define STORAGE_SALT_SIZE 4
#endif
enum storage_ui_message_t {
NO_MSG = 0,
VERIFYING_PIN_MSG,
PROCESSING_MSG,
STARTING_MSG,
WRONG_PIN_MSG,
};
typedef secbool (*PIN_UI_WAIT_CALLBACK)(uint32_t wait, uint32_t progress,
const char *message);
enum storage_ui_message_t message);
void storage_init(PIN_UI_WAIT_CALLBACK callback, const uint8_t *salt,
const uint16_t salt_len);

View File

@ -154,17 +154,12 @@ const uint8_t WIPE_CODE_EMPTY[] = {0, 0, 0, 0};
#define GUARD_KEY_MODULUS 6311
#define GUARD_KEY_REMAINDER 15
const char *const VERIFYING_PIN_MSG = "Verifying PIN";
const char *const PROCESSING_MSG = "Processing";
const char *const STARTING_MSG = "Starting up";
const char *const WRONG_PIN_MSG = "Wrong PIN";
static secbool initialized = secfalse;
static secbool unlocked = secfalse;
static PIN_UI_WAIT_CALLBACK ui_callback = NULL;
static uint32_t ui_total = 0;
static uint32_t ui_rem = 0;
static const char *ui_message = NULL;
static enum storage_ui_message_t ui_message = NO_MSG;
static uint8_t cached_keys[KEYS_SIZE] = {0};
static uint8_t *const cached_dek = cached_keys;
static uint8_t *const cached_sak = cached_keys + DEK_SIZE;
@ -1258,7 +1253,7 @@ secbool storage_unlock(const uint8_t *pin, size_t pin_len,
ui_total = PIN_DERIVE_MS;
ui_rem = ui_total;
if (pin_len == 0) {
if (ui_message == NULL) {
if (ui_message == NO_MSG) {
ui_message = STARTING_MSG;
} else {
ui_message = PROCESSING_MSG;

View File

@ -53,8 +53,16 @@ extern const uint8_t *PIN_EMPTY;
#define STORAGE_SALT_SIZE 4
#endif
enum storage_ui_message_t {
NO_MSG = 0,
VERIFYING_PIN_MSG,
PROCESSING_MSG,
STARTING_MSG,
WRONG_PIN_MSG,
};
typedef secbool (*PIN_UI_WAIT_CALLBACK)(uint32_t wait, uint32_t progress,
const char *message);
enum storage_ui_message_t message);
void storage_init(PIN_UI_WAIT_CALLBACK callback, const uint8_t *salt,
const uint16_t salt_len);