From b56f2cf23d2dfb6801f824241cc845cbada94ead Mon Sep 17 00:00:00 2001 From: Daniel Mueller Date: Sun, 14 Jul 2019 09:58:48 -0700 Subject: Supply ExecCtx to try_* op --- nitrocli/src/commands.rs | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs index 0337883..594ba5f 100644 --- a/nitrocli/src/commands.rs +++ b/nitrocli/src/commands.rs @@ -107,7 +107,7 @@ where &pin_entry, "Could not access the password safe", (), - move |_, pin| { + move |ctx, _, pin| { let pws = device .get_password_safe(pin) .map_err(|err| ((), Error::from(err)))?; @@ -129,7 +129,7 @@ fn authenticate<'mgr, D, A, F>( ) -> Result where D: Device<'mgr>, - F: Fn(D, &str) -> result::Result, + F: Fn(&mut args::ExecCtx<'_>, D, &str) -> result::Result, { let pin_entry = pinentry::PinEntry::from(pin_type, &device)?; @@ -149,7 +149,7 @@ where device, pinentry::PinType::User, "Could not authenticate as user", - |device, pin| device.authenticate_user(pin), + |_ctx, device, pin| device.authenticate_user(pin), ) } @@ -166,7 +166,7 @@ where device, pinentry::PinType::Admin, "Could not authenticate as admin", - |device, pin| device.authenticate_admin(pin), + |_ctx, device, pin| device.authenticate_admin(pin), ) } @@ -205,7 +205,7 @@ fn try_with_pin_and_data_with_pinentry( mut op: F, ) -> Result where - F: FnMut(D, &str) -> result::Result, + F: FnMut(&mut args::ExecCtx<'_>, D, &str) -> result::Result, E: crate::error::TryInto, { let mut data = data; @@ -213,7 +213,7 @@ where let mut error_msg = None; loop { let pin = pinentry::inquire(ctx, pin_entry, pinentry::Mode::Query, error_msg)?; - match op(data, &pin) { + match op(ctx, data, &pin) { Ok(result) => return Ok(result), Err((new_data, err)) => match err.try_into() { Ok(err) => match err { @@ -245,12 +245,13 @@ fn try_with_pin_and_data( mut op: F, ) -> Result where - F: FnMut(D, &str) -> result::Result, + F: FnMut(&mut args::ExecCtx<'_>, D, &str) -> result::Result, E: crate::error::TryInto, { let pin = match pin_entry.pin_type() { - pinentry::PinType::Admin => &ctx.admin_pin, - pinentry::PinType::User => &ctx.user_pin, + // TODO: Should not clone here :-| + pinentry::PinType::Admin => ctx.admin_pin.clone(), + pinentry::PinType::User => ctx.user_pin.clone(), }; if let Some(pin) = pin { @@ -260,7 +261,7 @@ where msg )) })?; - op(data, &pin).map_err(|(_, err)| match err.try_into() { + op(ctx, data, &pin).map_err(|(_, err)| match err.try_into() { Ok(err) => get_error(msg, err), Err(err) => err, }) @@ -283,7 +284,7 @@ where F: FnMut(&str) -> result::Result<(), E>, E: crate::error::TryInto, { - try_with_pin_and_data(ctx, pin_entry, msg, (), |data, pin| { + try_with_pin_and_data(ctx, pin_entry, msg, (), |_ctx, data, pin| { op(pin).map_err(|err| (data, err)) }) } -- cgit v1.2.1