keyfork-{shard,prompt}: add Yes/No prompt for verifying QR codes
This commit is contained in:
parent
739921d915
commit
e7be91bdd4
|
@ -23,7 +23,7 @@ use keyfork_prompt::{
|
|||
mnemonic::{MnemonicSetValidator, MnemonicValidator, WordLength},
|
||||
Validator,
|
||||
},
|
||||
Message as PromptMessage, PromptHandler,
|
||||
Message as PromptMessage, PromptHandler, YesNo,
|
||||
};
|
||||
use sha2::{Digest, Sha256};
|
||||
use x25519_dalek::{EphemeralSecret, PublicKey};
|
||||
|
@ -300,9 +300,19 @@ pub trait Format {
|
|||
let small_mnemonic = Mnemonic::from_raw_bytes(small_sum);
|
||||
|
||||
let mut prompt = prompt.lock().expect(bug!(POISONED_MUTEX));
|
||||
prompt.prompt_message(PromptMessage::Text(format!(
|
||||
"Is THIS your card???? If not, press ctrl+c!: {small_mnemonic}"
|
||||
let question =
|
||||
format!("Do these words match the expected words? {small_mnemonic}");
|
||||
let response = keyfork_prompt::prompt_choice(
|
||||
&mut **prompt,
|
||||
&question,
|
||||
&[YesNo::No, YesNo::Yes],
|
||||
)?;
|
||||
if response == YesNo::No {
|
||||
prompt.prompt_message(PromptMessage::Text(String::from(
|
||||
"Could not establish secure channel, exiting.",
|
||||
)))?;
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
pubkey_data = Some(data);
|
||||
break;
|
||||
|
|
|
@ -83,6 +83,34 @@ impl<T: Choice> Choice for &T {
|
|||
}
|
||||
}
|
||||
|
||||
/// A Yes/No Choice.
|
||||
#[derive(PartialEq, Eq, Clone, Copy)]
|
||||
pub enum YesNo {
|
||||
/// Yes.
|
||||
Yes,
|
||||
|
||||
/// No.
|
||||
No,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for YesNo {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
YesNo::Yes => f.write_str("Yes"),
|
||||
YesNo::No => f.write_str("No"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Choice for YesNo {
|
||||
fn identifier(&self) -> Option<char> {
|
||||
match self {
|
||||
YesNo::Yes => Some('y'),
|
||||
YesNo::No => Some('n'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub type BoxResult = std::result::Result<(), Box<dyn std::error::Error>>;
|
||||
|
||||
|
|
Loading…
Reference in New Issue