diff --git a/cli/src/commands/invite/claim.rs b/cli/src/commands/invite/claim.rs index 86cb77e199d..59a8917b106 100644 --- a/cli/src/commands/invite/claim.rs +++ b/cli/src/commands/invite/claim.rs @@ -2,6 +2,7 @@ use std::{path::PathBuf, sync::Arc}; +use anyhow::anyhow; use libparsec::{ internal::{ claimer_retrieve_info, AnyClaimRetrievedInfoCtx, DeviceClaimFinalizeCtx, @@ -20,7 +21,7 @@ use libparsec_client::{ }; use crate::utils::*; -use dialoguer::Select; +use dialoguer::{Input, Select}; crate::clap_parser_with_shared_opts_builder!( #[with = config_dir, data_dir, password_stdin] @@ -246,18 +247,17 @@ async fn step2_device(ctx: DeviceClaimInProgress1Ctx) -> anyhow::Result anyhow::Result { - let mut input = String::new(); let sas_codes = ctx.generate_greeter_sas_choices(3); - for (i, sas_code) in sas_codes.iter().enumerate() { - println!(" {i} - {YELLOW}{sas_code}{RESET}") + let selected_sas = Select::new() + .items(&sas_codes) + .with_prompt("Select code provided by greeter") + .interact()?; + if &sas_codes[selected_sas] != ctx.greeter_sas() { + Err(anyhow!("Invalid SAS code")) + } else { + Ok(ctx.do_signify_trust().await?) } - - println!("Select code provided by greeter (0, 1, 2)"); - - choose_sas_code(&mut input, &sas_codes, ctx.greeter_sas())?; - - Ok(ctx.do_signify_trust().await?) } /// Step 3: wait peer trust @@ -356,8 +356,7 @@ async fn step4_shamir( async fn step5_shamir( ctx: ShamirRecoveryClaimRecoverDeviceCtx, ) -> anyhow::Result { - let mut input = String::new(); - let device_label = choose_device_label(&mut input)?; + let device_label = Input::new().with_prompt("Enter device label").interact()?; let mut handle = start_spinner("Waiting for greeter".into()); diff --git a/cli/src/commands/invite/greet.rs b/cli/src/commands/invite/greet.rs index 814e12239f1..3f3615e638a 100644 --- a/cli/src/commands/invite/greet.rs +++ b/cli/src/commands/invite/greet.rs @@ -1,6 +1,7 @@ // Parsec Cloud (https://parsec.cloud) Copyright (c) BUSL-1.1 2016-present Scille SAS use anyhow::Context; +use dialoguer::Select; use libparsec::{ authenticated_cmds::latest::invite_list::InviteListItem, internal::{ @@ -83,6 +84,7 @@ async fn step0( let invitation = match invitations.into_iter().find(|invitation| match invitation { InviteListItem::User { token, .. } if *token == invitation_token => true, InviteListItem::Device { token, .. } if *token == invitation_token => true, + InviteListItem::ShamirRecovery { token, .. } if *token == invitation_token => true, _ => false, }) { Some(invitation) => invitation, @@ -213,17 +215,16 @@ async fn step3_device(ctx: DeviceGreetInProgress2Ctx) -> anyhow::Result anyhow::Result { - let mut input = String::new(); let sas_codes = ctx.generate_claimer_sas_choices(3); - for (i, sas_code) in sas_codes.iter().enumerate() { - println!(" {i} - {YELLOW}{sas_code}{RESET}") + let selected_sas = Select::new() + .items(&sas_codes) + .with_prompt("Select code provided by claimer") + .interact()?; + if &sas_codes[selected_sas] != ctx.claimer_sas() { + Err(anyhow::anyhow!("Invalid SAS code")) + } else { + Ok(ctx.do_signify_trust().await?) } - - println!("Select code provided by claimer (0, 1, 2)"); - - choose_sas_code(&mut input, &sas_codes, ctx.claimer_sas())?; - - Ok(ctx.do_signify_trust().await?) } /// Step 4: get claim requests