summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-07-14 09:58:48 -0700
committerRobin Krahl <robin.krahl@ireas.org>2019-07-14 21:19:04 +0200
commitb56f2cf23d2dfb6801f824241cc845cbada94ead (patch)
treef65d69e9817dc6638fd48ece5c3a377e00cea70a
parent794cdbee2a65c778d2172474085d253fd49c5d3d (diff)
downloadnitrocli-nitrokey-0.4-try-into.tar.gz
nitrocli-nitrokey-0.4-try-into.tar.bz2
Supply ExecCtx to try_* opnitrokey-0.4-try-into
-rw-r--r--nitrocli/src/commands.rs23
1 files 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<A>
where
D: Device<'mgr>,
- F: Fn(D, &str) -> result::Result<A, (D, nitrokey::Error)>,
+ F: Fn(&mut args::ExecCtx<'_>, D, &str) -> result::Result<A, (D, nitrokey::Error)>,
{
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<D, F, R, E>(
mut op: F,
) -> Result<R>
where
- F: FnMut(D, &str) -> result::Result<R, (D, E)>,
+ F: FnMut(&mut args::ExecCtx<'_>, D, &str) -> result::Result<R, (D, E)>,
E: crate::error::TryInto<nitrokey::Error>,
{
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<D, F, R, E>(
mut op: F,
) -> Result<R>
where
- F: FnMut(D, &str) -> result::Result<R, (D, E)>,
+ F: FnMut(&mut args::ExecCtx<'_>, D, &str) -> result::Result<R, (D, E)>,
E: crate::error::TryInto<nitrokey::Error>,
{
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<nitrokey::Error>,
{
- 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))
})
}