Skip to content

Commit

Permalink
ui/components/trinary_input_string: allow mode to enter only numbers.
Browse files Browse the repository at this point in the history
In BIP-85, the user needs to specify the index at which to derive a
secret. This change allows the keyboard input to be used to enter
integers.
  • Loading branch information
benma committed May 18, 2023
1 parent e0ae2ce commit 3279c68
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/rust/bitbox02/src/ui/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub struct TrinaryInputStringParams<'a> {
pub title: &'a str,
/// Currently specialized to the BIP39 wordlist. Can be extended if needed.
pub wordlist: Option<&'a crate::keystore::Bip39Wordlist>,
pub number_input: bool,
pub hide: bool,
pub special_chars: bool,
pub longtouch: bool,
Expand Down Expand Up @@ -132,6 +133,7 @@ impl<'a> TrinaryInputStringParams<'a> {
None => 0,
Some(wordlist) => wordlist.len() as _,
},
number_input: self.number_input,
hide: self.hide,
special_chars: self.special_chars,
longtouch: self.longtouch,
Expand Down
10 changes: 9 additions & 1 deletion src/ui/components/trinary_input_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct {
// Can be NULL.
const char* const* wordlist;
size_t wordlist_size;
bool number_input;
// Only applies if wordlist != NULL: determines if a word from the wordlist was entered.
bool can_confirm;
// Mask user input with '*'?
Expand Down Expand Up @@ -294,6 +295,8 @@ static void _set_alphabet(component_t* trinary_input_string)
}
// Since wordlist is sorted, charset is sorted automatically.
trinary_input_char_set_alphabet(trinary_char, charset, 1);
} else if (data->number_input) {
trinary_input_char_set_alphabet(trinary_char, _digits, 1);
} else {
// Otherwise set the input charset based on the user selected keyboard mode.
keyboard_mode_t keyboard_mode = keyboard_current_mode(data->keyboard_switch_component);
Expand Down Expand Up @@ -450,12 +453,17 @@ component_t* trinary_input_string_create(
memset(component, 0, sizeof(component_t));
memset(data, 0, sizeof(data_t));

if (params->number_input && data->wordlist != NULL) {
Abort("trinary_input_string: invalid params");
}

data->confirm_cb = confirm_cb;
data->confirm_callback_param = confirm_callback_param;
data->cancel_cb = cancel_cb;
data->cancel_callback_param = cancel_callback_param;
data->wordlist = params->wordlist;
data->wordlist_size = params->wordlist_size;
data->number_input = params->number_input;
data->hide = params->hide;
data->longtouch = params->longtouch;
data->cancel_is_backbutton = params->cancel_is_backbutton;
Expand All @@ -481,7 +489,7 @@ component_t* trinary_input_string_create(
data->confirm_component = confirm_button_create(params->longtouch, ICON_BUTTON_CHECK);
ui_util_add_sub_component(component, data->confirm_component);

if (params->wordlist == NULL) {
if (params->wordlist == NULL && !params->number_input) {
data->keyboard_switch_component =
keyboard_switch_create(top_slider, params->special_chars, component);
ui_util_add_sub_component(component, data->keyboard_switch_component);
Expand Down
2 changes: 2 additions & 0 deletions src/ui/components/trinary_input_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ typedef struct {
const char* title;
// Restrict and autocomplete to this list of words. Set to NULL to allow arbitrary input.
const char* const* wordlist;
// If true, the user can enter numbers only.
bool number_input;
// Set to 0 if wordlist is NULL.
size_t wordlist_size;
// Mask the chars entered as `*`. For password input.
Expand Down

0 comments on commit 3279c68

Please sign in to comment.