summaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
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(), ' ');
}