added flag to retry open command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
shimun 2019-10-12 22:46:54 +02:00
parent 2bac911b32
commit 5d1c7beb4d
Signed by: shimun
GPG Key ID: E81D8382DC2F971B

View File

@ -174,6 +174,8 @@ pub enum Command {
device: PathBuf, device: PathBuf,
#[structopt(env = "FIDO2LUKS_MAPPER_NAME")] #[structopt(env = "FIDO2LUKS_MAPPER_NAME")]
name: String, name: String,
#[structopt(short = "r", long = "max-retries", default_value = "0")]
retries: i32,
#[structopt(flatten)] #[structopt(flatten)]
secret_gen: SecretGeneration, secret_gen: SecretGeneration,
}, },
@ -265,10 +267,24 @@ pub fn run_cli() -> Fido2LuksResult<()> {
Command::Open { Command::Open {
device, device,
name, name,
retries,
ref secret_gen, ref secret_gen,
} => { } => {
let mut retries = *retries;
loop {
let secret = secret_gen.patch(&args).obtain_secret()?; let secret = secret_gen.patch(&args).obtain_secret()?;
open_container(&device, &name, &secret) match open_container(&device, &name, &secret) {
Err(e) => match e {
Fido2LuksError::WrongSecret if retries > 0 => {
retries -= 1;
eprintln!("{}", e);
continue;
}
e => Err(e)?,
},
res => break res,
}
}
} }
Command::Connected => match get_devices() { Command::Connected => match get_devices() {
Ok(ref devs) if !devs.is_empty() => { Ok(ref devs) if !devs.is_empty() => {