aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/error.rs
diff options
context:
space:
mode:
authorDaniel Mueller <deso@posteo.net>2019-07-14 19:19:04 -0700
committerDaniel Mueller <deso@posteo.net>2019-07-14 19:19:04 -0700
commit49f5194e16db47b6de9847b79840c6fe35e0df8c (patch)
tree613e28edd2cfc542045ea32ec6e86afc2ccf04e7 /nitrocli/src/error.rs
parentf3a1b0b3c3cd628ecbfa45c3023956d44a4154a4 (diff)
downloadnitrocli-49f5194e16db47b6de9847b79840c6fe35e0df8c.tar.gz
nitrocli-49f5194e16db47b6de9847b79840c6fe35e0df8c.tar.bz2
Introduce with_password_safe function
Similar to the with_*device functions introduced in a previous change, this change introduces a with_password_safe function that is a short hand for opening the Nitrokey, retrieving a handle to the password safe, and invoking a user-supplied function on it. This function will allow us to prevent life time inference problems caused by passing around a PasswordSafe object, which will contain an additional reference (and with that, lifetime) in nitrokey version 0.4.
Diffstat (limited to 'nitrocli/src/error.rs')
-rw-r--r--nitrocli/src/error.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/nitrocli/src/error.rs b/nitrocli/src/error.rs
index d1eb2eb..c0e7403 100644
--- a/nitrocli/src/error.rs
+++ b/nitrocli/src/error.rs
@@ -47,6 +47,15 @@ pub enum Error {
Error(String),
}
+impl TryInto<nitrokey::CommandError> for Error {
+ fn try_into(self) -> Result<nitrokey::CommandError, Error> {
+ match self {
+ Error::CommandError(_, err) => Ok(err),
+ err => Err(err),
+ }
+ }
+}
+
impl From<&str> for Error {
fn from(s: &str) -> Error {
Error::Error(s.to_string())