aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <robin.krahl@ireas.org>2019-01-30 19:20:37 +0000
committerRobin Krahl <robin.krahl@ireas.org>2019-07-14 13:49:49 +0000
commitd4efc5026fd96c3e19df928cfdbed2774c04d743 (patch)
tree4b56b8c2ec042137eeb74743bf351db96dac0853
parentbccf3d17ac2376a2b297491212bf53e54d71f76c (diff)
downloadnitrocli-d4efc5026fd96c3e19df928cfdbed2774c04d743.tar.gz
nitrocli-d4efc5026fd96c3e19df928cfdbed2774c04d743.tar.bz2
Replace nitrokey::CommandError with nitrokey::Error
Previously, CommandError was nitrokey-rs’s main error type. Since nitrokey-rs v0.4.0, Error replaced CommandError, which now is an Error variant. This patch changes the error handling code in nitrocli to work with the new Error type.
-rw-r--r--nitrocli/src/commands.rs22
-rw-r--r--nitrocli/src/error.rs6
2 files changed, 14 insertions, 14 deletions
diff --git a/nitrocli/src/commands.rs b/nitrocli/src/commands.rs
index eb071ff..ff39a12 100644
--- a/nitrocli/src/commands.rs
+++ b/nitrocli/src/commands.rs
@@ -37,7 +37,7 @@ use crate::Result;
const NITROKEY_DEFAULT_ADMIN_PIN: &str = "12345678";
/// Create an `error::Error` with an error message of the format `msg: err`.
-fn get_error(msg: &'static str, err: nitrokey::CommandError) -> Error {
+fn get_error(msg: &'static str, err: nitrokey::Error) -> Error {
Error::CommandError(Some(msg), err)
}
@@ -139,7 +139,7 @@ fn authenticate<D, A, F>(
) -> Result<A>
where
D: Device,
- F: Fn(D, &str) -> result::Result<A, (D, nitrokey::CommandError)>,
+ F: Fn(D, &str) -> result::Result<A, (D, nitrokey::Error)>,
{
let pin_entry = pinentry::PinEntry::from(pin_type, &device)?;
@@ -209,7 +209,7 @@ fn try_with_pin_and_data_with_pinentry<D, F, R>(
op: F,
) -> Result<R>
where
- F: Fn(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>,
+ F: Fn(D, &str) -> result::Result<R, (D, nitrokey::Error)>,
{
let mut data = data;
let mut retry = 3;
@@ -219,7 +219,7 @@ where
match op(data, &pin) {
Ok(result) => return Ok(result),
Err((new_data, err)) => match err {
- nitrokey::CommandError::WrongPassword => {
+ nitrokey::Error::CommandError(nitrokey::CommandError::WrongPassword) => {
pinentry::clear(pin_entry)?;
retry -= 1;
@@ -245,7 +245,7 @@ fn try_with_pin_and_data<D, F, R>(
op: F,
) -> Result<R>
where
- F: Fn(D, &str) -> result::Result<R, (D, nitrokey::CommandError)>,
+ F: Fn(D, &str) -> result::Result<R, (D, nitrokey::Error)>,
{
let pin = match pin_entry.pin_type() {
pinentry::PinType::Admin => &ctx.admin_pin,
@@ -276,7 +276,7 @@ fn try_with_pin<F>(
op: F,
) -> Result<()>
where
- F: Fn(&str) -> result::Result<(), nitrokey::CommandError>,
+ F: Fn(&str) -> result::Result<(), nitrokey::Error>,
{
try_with_pin_and_data(ctx, pin_entry, msg, (), |data, pin| {
op(pin).map_err(|err| (data, err))
@@ -702,8 +702,8 @@ fn print_otp_status(
};
let name = match result {
Ok(name) => name,
- Err(nitrokey::CommandError::InvalidSlot) => return Ok(()),
- Err(nitrokey::CommandError::SlotNotProgrammed) => {
+ Err(nitrokey::Error::LibraryError(nitrokey::LibraryError::InvalidSlot)) => return Ok(()),
+ Err(nitrokey::Error::CommandError(nitrokey::CommandError::SlotNotProgrammed)) => {
if all {
"[not programmed]".to_string()
} else {
@@ -816,7 +816,7 @@ pub fn pin_unblock(ctx: &mut args::ExecCtx<'_>) -> Result<()> {
fn print_pws_data(
ctx: &mut args::ExecCtx<'_>,
description: &'static str,
- result: result::Result<String, nitrokey::CommandError>,
+ result: result::Result<String, nitrokey::Error>,
quiet: bool,
) -> Result<()> {
let value = result.map_err(|err| get_error("Could not access PWS slot", err))?;
@@ -830,7 +830,7 @@ fn print_pws_data(
fn check_slot(pws: &nitrokey::PasswordSafe<'_>, slot: u8) -> Result<()> {
if slot >= nitrokey::SLOT_COUNT {
- return Err(nitrokey::CommandError::InvalidSlot.into());
+ return Err(nitrokey::Error::from(nitrokey::LibraryError::InvalidSlot).into());
}
let status = pws
.get_slot_status()
@@ -840,7 +840,7 @@ fn check_slot(pws: &nitrokey::PasswordSafe<'_>, slot: u8) -> Result<()> {
} else {
Err(get_error(
"Could not access PWS slot",
- nitrokey::CommandError::SlotNotProgrammed,
+ nitrokey::CommandError::SlotNotProgrammed.into(),
))
}
}
diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs
index 1346526..f18d1a1 100644
--- a/nitrocli/src/error.rs
+++ b/nitrocli/src/error.rs
@@ -25,7 +25,7 @@ use std::string;
#[derive(Debug)]
pub enum Error {
ArgparseError(i32),
- CommandError(Option<&'static str>, nitrokey::CommandError),
+ CommandError(Option<&'static str>, nitrokey::Error),
IoError(io::Error),
Utf8Error(str::Utf8Error),
Error(String),
@@ -37,8 +37,8 @@ impl From<&str> for Error {
}
}
-impl From<nitrokey::CommandError> for Error {
- fn from(e: nitrokey::CommandError) -> Error {
+impl From<nitrokey::Error> for Error {
+ fn from(e: nitrokey::Error) -> Error {
Error::CommandError(None, e)
}
}