summaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2018-07-07 21:24:14 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2018-07-07 21:24:14 +0200
commit430e4b4116ec00c4875170642f8ae04bc3497d88 (patch)
treed158fe787ecf1b20cd906dda712ecee8f7285a59 /NK_C_API.cc
parent4b3b21dfe6958376db3b1fbcadf6e03f53291e4f (diff)
parent601f43bfa71b479e32a289eaeec75069cbc7c26f (diff)
downloadlibnitrokey-430e4b4116ec00c4875170642f8ae04bc3497d88.tar.gz
libnitrokey-430e4b4116ec00c4875170642f8ae04bc3497d88.tar.bz2
Merge branch 'pr_116'v3.4
Allow to connect to device with model specified by enum. Fixes #116
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 1d9ff4f..7d0a10e 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -156,6 +156,7 @@ extern "C" {
case NK_STORAGE:
model_string = "S";
break;
+ case NK_DISCONNECTED:
default:
/* no such enum value -- return error code */
return 0;
@@ -224,6 +225,25 @@ extern "C" {
}
+ NK_C_API enum NK_device_model NK_get_device_model() {
+ auto m = NitrokeyManager::instance();
+ try {
+ auto model = m->get_connected_device_model();
+ switch (model) {
+ case DeviceModel::PRO:
+ return NK_PRO;
+ case DeviceModel::STORAGE:
+ return NK_STORAGE;
+ default:
+ /* unknown or not connected device */
+ return NK_device_model::NK_DISCONNECTED;
+ }
+ } catch (const DeviceNotConnected& e) {
+ return NK_device_model::NK_DISCONNECTED;
+ }
+}
+
+
void clear_string(std::string &s) {
std::fill(s.begin(), s.end(), ' ');
}