aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/commands.rs
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-07-11 17:44:44 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-14 14:07:51 +0000
commit0e1942a6ca93aa3ab1b93778915320a055bb7744 (patch)
treefb2645729d7574b3a1b7d280e7eb74f3864680ef /nitrocli/src/commands.rs
parentd4774619df3088e751c3100807e198d75a832ebd (diff)
downloadnitrocli-0e1942a6ca93aa3ab1b93778915320a055bb7744.tar.gz
nitrocli-0e1942a6ca93aa3ab1b93778915320a055bb7744.tar.bz2
lifetimes for Device/DeviceWrapper/User/Admin
Diffstat (limited to 'nitrocli/src/commands.rs')
-rw-r--r--nitrocli/src/commands.rs52
1 files changed, 23 insertions, 29 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index 869e667..260774a 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -57,7 +57,7 @@ fn set_log_level(ctx: &mut args::ExecCtx<'_>) {
fn with_device<F>(ctx: &mut args::ExecCtx<'_>, op: F) -> Result<()>
where
- F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::DeviceWrapper) -> Result<()>,
+ F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::DeviceWrapper<'_>) -> Result<()>,
{
let mut manager = nitrokey::take()?;
set_log_level(ctx);
@@ -73,7 +73,7 @@ where
fn with_storage_device<F>(ctx: &mut args::ExecCtx<'_>, op: F) -> Result<()>
where
- F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::Storage) -> Result<()>,
+ F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::Storage<'_>) -> Result<()>,
{
let mut manager = nitrokey::take()?;
set_log_level(ctx);
@@ -92,38 +92,26 @@ where
op(ctx, device)
}
-/// Open the password safe on the given device.
-fn get_password_safe<'dev, D>(
- ctx: &mut args::ExecCtx<'_>,
- device: &'dev mut D,
-) -> Result<nitrokey::PasswordSafe<'dev>>
+fn with_password_safe<'dev, D, F>(ctx: &mut args::ExecCtx<'_>, device: &mut D, op: F) -> Result<()>
where
- D: Device,
+ D: Device<'dev>,
+ F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::PasswordSafe<'_, '_>) -> Result<()>,
{
let pin_entry = pinentry::PinEntry::from(pinentry::PinType::User, device)?;
-
- try_with_pin_and_data(
+ let pws = try_with_pin_and_data(
ctx,
&pin_entry,
"Could not access the password safe",
(),
|_, pin| device.get_password_safe(pin).map_err(|err| ((), err)),
- )
-}
-
-fn with_password_safe<D, F>(ctx: &mut args::ExecCtx<'_>, device: &mut D, op: F) -> Result<()>
-where
- D: Device,
- F: FnOnce(&mut args::ExecCtx<'_>, nitrokey::PasswordSafe<'_>) -> Result<()>,
-{
- let pws = get_password_safe(ctx, device)?;
+ )?;
op(ctx, pws)
}
/// Authenticate the given device using the given PIN type and operation.
///
/// If an error occurs, the error message `msg` is used.
-fn authenticate<D, A, F>(
+fn authenticate<'mgr, D, A, F>(
ctx: &mut args::ExecCtx<'_>,
device: D,
pin_type: pinentry::PinType,
@@ -131,7 +119,7 @@ fn authenticate<D, A, F>(
op: F,
) -> Result<A>
where
- D: Device,
+ D: Device<'mgr>,
F: Fn(D, &str) -> result::Result<A, (D, nitrokey::Error)>,
{
let pin_entry = pinentry::PinEntry::from(pin_type, &device)?;
@@ -140,9 +128,12 @@ where
}
/// Authenticate the given device with the user PIN.
-fn authenticate_user<T>(ctx: &mut args::ExecCtx<'_>, device: T) -> Result<nitrokey::User<T>>
+fn authenticate_user<'mgr, T>(
+ ctx: &mut args::ExecCtx<'_>,
+ device: T,
+) -> Result<nitrokey::User<'mgr, T>>
where
- T: Device,
+ T: Device<'mgr>,
{
authenticate(
ctx,
@@ -154,9 +145,12 @@ where
}
/// Authenticate the given device with the admin PIN.
-fn authenticate_admin<T>(ctx: &mut args::ExecCtx<'_>, device: T) -> Result<nitrokey::Admin<T>>
+fn authenticate_admin<'mgr, T>(
+ ctx: &mut args::ExecCtx<'_>,
+ device: T,
+) -> Result<nitrokey::Admin<'mgr, T>>
where
- T: Device,
+ T: Device<'mgr>,
{
authenticate(
ctx,
@@ -313,7 +307,7 @@ fn print_storage_status(
fn print_status(
ctx: &mut args::ExecCtx<'_>,
model: &'static str,
- device: &nitrokey::DeviceWrapper,
+ device: &nitrokey::DeviceWrapper<'_>,
) -> Result<()> {
let serial_number = device
.get_serial_number()
@@ -681,7 +675,7 @@ pub fn otp_clear(
fn print_otp_status(
ctx: &mut args::ExecCtx<'_>,
algorithm: args::OtpAlgorithm,
- device: &nitrokey::DeviceWrapper,
+ device: &nitrokey::DeviceWrapper<'_>,
all: bool,
) -> Result<()> {
let mut slot: u8 = 0;
@@ -824,7 +818,7 @@ fn print_pws_data(
Ok(())
}
-fn check_slot(pws: &nitrokey::PasswordSafe<'_>, slot: u8) -> Result<()> {
+fn check_slot(pws: &nitrokey::PasswordSafe<'_, '_>, slot: u8) -> Result<()> {
if slot >= nitrokey::SLOT_COUNT {
return Err(nitrokey::Error::from(nitrokey::LibraryError::InvalidSlot).into());
}
@@ -899,7 +893,7 @@ pub fn pws_clear(ctx: &mut args::ExecCtx<'_>, slot: u8) -> Result<()> {
fn print_pws_slot(
ctx: &mut args::ExecCtx<'_>,
- pws: &nitrokey::PasswordSafe<'_>,
+ pws: &nitrokey::PasswordSafe<'_, '_>,
slot: usize,
programmed: bool,
) -> Result<()> {