aboutsummaryrefslogtreecommitdiff
path: root/device.cc
diff options
context:
space:
mode:
Diffstat (limited to 'device.cc')
-rw-r--r--device.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/device.cc b/device.cc
index 80e4b38..ef295e8 100644
--- a/device.cc
+++ b/device.cc
@@ -29,6 +29,7 @@
#include "libnitrokey/device.h"
#include "libnitrokey/log.h"
#include <mutex>
+#include <codecvt>
#include "DeviceCommunicationExceptions.h"
#include "device.h"
@@ -96,7 +97,13 @@ bool Device::_connect() {
// hid_init(); // done automatically on hid_open
if (m_path.empty()){
- mp_devhandle = hid_open(m_vid, m_pid, nullptr);
+ const wchar_t* serial = nullptr;
+ if (!m_serial.empty()){
+ std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
+ auto wstr = converter.from_bytes(m_serial.c_str());
+ serial = wstr.c_str();
+ }
+ mp_devhandle = hid_open(m_vid, m_pid, serial);
} else {
mp_devhandle = hid_open_path(m_path.c_str());
}
@@ -105,6 +112,10 @@ bool Device::_connect() {
return success;
}
+void Device::set_serial(const std::string serial){
+ m_serial = serial;
+}
+
void Device::set_path(const std::string path){
m_path = path;
}