aboutsummaryrefslogtreecommitdiff
path: root/src/args.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/args.rs b/src/args.rs
index 8af38ca..e4bc77d 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -3,6 +3,8 @@
// Copyright (C) 2020 The Nitrocli Developers
// SPDX-License-Identifier: GPL-3.0-or-later
+use std::convert;
+
/// Provides access to a Nitrokey device
#[derive(Debug, structopt::StructOpt)]
#[structopt(name = "nitrocli")]
@@ -59,6 +61,18 @@ impl From<DeviceModel> for nitrokey::Model {
}
}
+impl convert::TryFrom<nitrokey::Model> for DeviceModel {
+ type Error = anyhow::Error;
+
+ fn try_from(model: nitrokey::Model) -> Result<DeviceModel, anyhow::Error> {
+ match model {
+ nitrokey::Model::Pro => Ok(DeviceModel::Pro),
+ nitrokey::Model::Storage => Ok(DeviceModel::Storage),
+ _ => Err(anyhow::anyhow!("Unsupported device model: {}", model)),
+ }
+ }
+}
+
impl<'de> serde::Deserialize<'de> for DeviceModel {
fn deserialize<D>(deserializer: D) -> Result<DeviceModel, D::Error>
where