Skip to content

Commit e66abab

Browse files
committed
workflow/password: add PasswordType enum
To distinguish between password and passphrase. This will make it easier to adapt the password screen, where we want to make the digits the default keyboard for the BB02+.
1 parent ea1480e commit e66abab

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

src/rust/bitbox02-rust/src/workflow/password.rs

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,34 @@ async fn prompt_cancel(hal: &mut impl crate::hal::Hal) -> Result<(), confirm::Us
2727
.await
2828
}
2929

30+
pub enum PasswordType {
31+
/// The password to be entered is the device unlock password.
32+
DevicePassword,
33+
/// The password to be entered is the BIP39 passphrase.
34+
Bip39Passphrase,
35+
}
36+
3037
/// If `can_cancel` is `Yes`, the workflow can be cancelled.
3138
/// If it is no, the result is always `Ok(())`.
3239
///
3340
/// Example:
3441
/// ```no_run
35-
/// let pw = enter("Enter password", true, CanCancel::No).await.unwrap();
42+
/// let pw = enter(hal, "Enter password", PassswordType::DevicePassword, CanCancel::No).await.unwrap();
3643
/// // use pw.
3744
/// ```
3845
pub async fn enter(
3946
hal: &mut impl crate::hal::Hal,
4047
title: &str,
41-
special_chars: bool,
48+
password_type: PasswordType,
4249
can_cancel: CanCancel,
4350
) -> Result<zeroize::Zeroizing<String>, Error> {
4451
let params = trinary_input_string::Params {
4552
title,
4653
hide: true,
47-
special_chars,
54+
special_chars: match password_type {
55+
PasswordType::DevicePassword => false,
56+
PasswordType::Bip39Passphrase => true,
57+
},
4858
longtouch: true,
4959
..Default::default()
5060
};
@@ -84,8 +94,20 @@ impl core::convert::From<Error> for EnterTwiceError {
8494
pub async fn enter_twice(
8595
hal: &mut impl crate::hal::Hal,
8696
) -> Result<zeroize::Zeroizing<String>, EnterTwiceError> {
87-
let password = enter(hal, "Set password", false, CanCancel::Yes).await?;
88-
let password_repeat = enter(hal, "Repeat password", false, CanCancel::Yes).await?;
97+
let password = enter(
98+
hal,
99+
"Set password",
100+
PasswordType::DevicePassword,
101+
CanCancel::Yes,
102+
)
103+
.await?;
104+
let password_repeat = enter(
105+
hal,
106+
"Repeat password",
107+
PasswordType::DevicePassword,
108+
CanCancel::Yes,
109+
)
110+
.await?;
89111
if password.as_str() != password_repeat.as_str() {
90112
hal.ui().status("Passwords\ndo not match", false).await;
91113
return Err(EnterTwiceError::DoNotMatch);

src/rust/bitbox02-rust/src/workflow/unlock.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@ pub async fn unlock_keystore(
7676
title: &str,
7777
can_cancel: password::CanCancel,
7878
) -> Result<(), UnlockError> {
79-
let password = password::enter(hal, title, false, can_cancel).await?;
79+
let password = password::enter(
80+
hal,
81+
title,
82+
password::PasswordType::DevicePassword,
83+
can_cancel,
84+
)
85+
.await?;
8086

8187
match keystore::unlock(&password) {
8288
Ok(()) => Ok(()),
@@ -106,10 +112,14 @@ pub async fn unlock_bip39(hal: &mut impl crate::hal::Hal) {
106112
if bitbox02::memory::is_mnemonic_passphrase_enabled() {
107113
// Loop until the user confirms.
108114
loop {
109-
mnemonic_passphrase =
110-
password::enter(hal, "Optional passphrase", true, password::CanCancel::No)
111-
.await
112-
.expect("not cancelable");
115+
mnemonic_passphrase = password::enter(
116+
hal,
117+
"Optional passphrase",
118+
password::PasswordType::Bip39Passphrase,
119+
password::CanCancel::No,
120+
)
121+
.await
122+
.expect("not cancelable");
113123

114124
if let Ok(()) = confirm_mnemonic_passphrase(hal, mnemonic_passphrase.as_str()).await {
115125
break;

0 commit comments

Comments
 (0)