summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2019-01-13 12:05:00 +0100
committerRobin Krahl <me@robin-krahl.de>2019-01-13 13:27:12 +0100
commit8979b7301f79e167a8060772cf83913703f70f2c (patch)
tree032325e709781b70d920f135c0d1931753b6dfa0
parent4f7c1b31191d98904276fecd236e6b68b405c349 (diff)
downloadlibnitrokey-8979b7301f79e167a8060772cf83913703f70f2c.tar.gz
libnitrokey-8979b7301f79e167a8060772cf83913703f70f2c.tar.bz2
Change NitrokeyManager::connect_with_path to also work with Pro
Previously, Stick20 was hardcoded in connect_with_path. Now we first use hid_enumerate to find out the model on that path, then we connect to that model. We also could have added the model as a parameter to connect_with_path. Yet we cannot directly check the model after connecting, so this would be error-prone.
-rw-r--r--NitrokeyManager.cc22
1 files changed, 21 insertions, 1 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 3b57ba6..99f0b7a 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -29,6 +29,7 @@
#include "libnitrokey/misc.h"
#include <mutex>
#include "libnitrokey/cxx_semantics.h"
+#include "libnitrokey/misc.h"
#include <functional>
#include <stick10_commands.h>
@@ -216,7 +217,26 @@ using nitrokey::misc::strcpyT;
}
}
- auto p = make_shared<Stick20>();
+ auto info_ptr = hid_enumerate(NITROKEY_VID, 0);
+ auto first_info_ptr = info_ptr;
+ if (!info_ptr)
+ return false;
+
+ misc::Option<DeviceModel> model;
+ while (info_ptr && !model.has_value()) {
+ if (path == std::string(info_ptr->path)) {
+ model = product_id_to_model(info_ptr->product_id);
+ }
+ info_ptr = info_ptr->next;
+ }
+ hid_free_enumeration(first_info_ptr);
+
+ if (!model.has_value())
+ return false;
+
+ auto p = Device::create(model.value());
+ if (!p)
+ return false;
p->set_path(path);
if(!p->connect()) return false;