aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Krahl <me@robin-krahl.de>2019-01-13 12:05:28 +0100
committerRobin Krahl <me@robin-krahl.de>2019-01-13 13:27:31 +0100
commita80378e0c770a503ddaafc0c7aacb78cac667b8f (patch)
tree447e63e584b111f7271e55c64427edc126c57ec2
parent2c79c15dc9aa4ec7eca454b793bf43a9a3ba85db (diff)
downloadlibnitrokey-a80378e0c770a503ddaafc0c7aacb78cac667b8f.tar.gz
libnitrokey-a80378e0c770a503ddaafc0c7aacb78cac667b8f.tar.bz2
Change std::wstring to std::string in DeviceInfo
For easier handling, we should use a std::string instead of std::wstring for the serial number in DeviceInfo. For the conversion, I assume that the serial number is valid UTF-8. As it should be alphanumeric and ASCII only, this should be true.
-rw-r--r--device.cc6
-rw-r--r--libnitrokey/device.h2
-rw-r--r--unittest/test_multiple_devices.cc10
3 files changed, 10 insertions, 8 deletions
diff --git a/device.cc b/device.cc
index 35aefca..bc42965 100644
--- a/device.cc
+++ b/device.cc
@@ -20,7 +20,9 @@
*/
#include <chrono>
+#include <codecvt>
#include <iostream>
+#include <locale>
#include <thread>
#include <cstddef>
#include <stdexcept>
@@ -210,7 +212,9 @@ std::vector<DeviceInfo> Device::enumerate(){
auto deviceModel = product_id_to_model(pInfo->product_id);
if (deviceModel.has_value()) {
std::string path(pInfo->path);
- std::wstring serialNumber(pInfo->serial_number);
+ std::wstring serialNumberW(pInfo->serial_number);
+ std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
+ std::string serialNumber = converter.to_bytes(serialNumberW);
DeviceInfo info = { deviceModel.value(), path, serialNumber };
res.push_back(info);
}
diff --git a/libnitrokey/device.h b/libnitrokey/device.h
index 4b1c239..d50080d 100644
--- a/libnitrokey/device.h
+++ b/libnitrokey/device.h
@@ -92,7 +92,7 @@ struct DeviceInfo {
/**
* The serial number of the device.
*/
- std::wstring m_serialNumber;
+ std::string m_serialNumber;
};
#include <atomic>
diff --git a/unittest/test_multiple_devices.cc b/unittest/test_multiple_devices.cc
index d644cfd..bc1b60b 100644
--- a/unittest/test_multiple_devices.cc
+++ b/unittest/test_multiple_devices.cc
@@ -42,9 +42,8 @@ TEST_CASE("List devices", "[BASIC]") {
std::cout << "Could not create device with model " << i.m_deviceModel << "\n";
continue;
}
- std::cout << i.m_deviceModel << " " << i.m_path << " ";
- std::wcout << i.m_serialNumber;
- std::cout << " |";
+ std::cout << i.m_deviceModel << " " << i.m_path << " "
+ << i.m_serialNumber << " |";
d->set_path(i.m_path);
d->connect();
auto res = GetStatus::CommandTransaction::run(d);
@@ -116,9 +115,8 @@ TEST_CASE("Use API", "[BASIC]") {
REQUIRE(v.size() > 0);
for (auto i : v) {
- std::cout << "Connect with: " << i.m_deviceModel << " " << i.m_path << " ";
- std::wcout << i.m_serialNumber;
- std::cout << " | " << std::boolalpha << nm->connect_with_path(i.m_path) << " |";
+ std::cout << "Connect with: " << i.m_deviceModel << " " << i.m_path << " "
+ << i.m_serialNumber << " | " << std::boolalpha << nm->connect_with_path(i.m_path) << " |";
try {
auto status = nm->get_status();
std::cout << " " << status.card_serial_u32 << " "