aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2019-01-13 12:03:43 +0100
committerRobin Krahl <me@robin-krahl.de>2019-01-13 12:03:43 +0100
commit71d4ecc04c23342f207e7f1133ea8824a1dcdd16 (patch)
tree2c51eeb8fee8fc928cd1f32040b0140088507b50
parent4a7ce051bd4004fb62f1c7022d92efa2ce42b6ab (diff)
downloadlibnitrokey-71d4ecc04c23342f207e7f1133ea8824a1dcdd16.tar.gz
libnitrokey-71d4ecc04c23342f207e7f1133ea8824a1dcdd16.tar.bz2
Change Nitrokey::list_devices return type to use DeviceInfo
In the previous commit, we changed the return value of Device::enumerate to std::vector<DeviceInfo>. Now we change Nitrokey::list_devices to also return DeviceInfo instances.
-rw-r--r--NitrokeyManager.cc9
-rw-r--r--libnitrokey/NitrokeyManager.h2
-rw-r--r--unittest/test_multiple_devices.cc5
3 files changed, 7 insertions, 9 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 8825fce..8ca4698 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -105,16 +105,11 @@ using nitrokey::misc::strcpyT;
return true;
}
- std::vector<std::string> NitrokeyManager::list_devices(){
+ std::vector<DeviceInfo> NitrokeyManager::list_devices(){
std::lock_guard<std::mutex> lock(mex_dev_com_manager);
auto p = make_shared<Stick20>();
- auto device_infos = p->enumerate();
- std::vector<std::string> strings;
- strings.resize(device_infos.size());
- std::transform(device_infos.begin(), device_infos.end(), strings.begin(),
- [](auto device_info) { return device_info.m_path; });
- return strings;
+ return p->enumerate();
}
std::vector<std::string> NitrokeyManager::list_devices_by_cpuID(){
diff --git a/libnitrokey/NitrokeyManager.h b/libnitrokey/NitrokeyManager.h
index d6e5df4..6908143 100644
--- a/libnitrokey/NitrokeyManager.h
+++ b/libnitrokey/NitrokeyManager.h
@@ -80,7 +80,7 @@ char * strndup(const char* str, size_t maxlen);
bool get_time(uint64_t time = 0);
bool erase_totp_slot(uint8_t slot_number, const char *temporary_password);
bool erase_hotp_slot(uint8_t slot_number, const char *temporary_password);
- std::vector<std::string> list_devices();
+ std::vector<DeviceInfo> list_devices();
std::vector<std::string> list_devices_by_cpuID();
/**
diff --git a/unittest/test_multiple_devices.cc b/unittest/test_multiple_devices.cc
index b224653..f9e9ad2 100644
--- a/unittest/test_multiple_devices.cc
+++ b/unittest/test_multiple_devices.cc
@@ -90,7 +90,10 @@ TEST_CASE("Use API", "[BASIC]") {
REQUIRE(v.size() > 0);
for (int i=0; i<10; i++){
- for (auto a : v) {
+ for (auto i : v) {
+ if (i.m_deviceModel != DeviceModel::STORAGE)
+ continue;
+ auto a = i.m_path;
std::cout <<"Connect with: " << a <<
" " << std::boolalpha << nm->connect_with_path(a) << " ";
try{