From 8979b7301f79e167a8060772cf83913703f70f2c Mon Sep 17 00:00:00 2001 From: Robin Krahl Date: Sun, 13 Jan 2019 12:05:00 +0100 Subject: 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. --- NitrokeyManager.cc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 #include "libnitrokey/cxx_semantics.h" +#include "libnitrokey/misc.h" #include #include @@ -216,7 +217,26 @@ using nitrokey::misc::strcpyT; } } - auto p = make_shared(); + auto info_ptr = hid_enumerate(NITROKEY_VID, 0); + auto first_info_ptr = info_ptr; + if (!info_ptr) + return false; + + misc::Option 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; -- cgit v1.2.3