From ab0f01c381c16ed61b8258582869912d4c38cbb7 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 28 Jun 2017 11:57:21 +0200 Subject: Adjust code to make compilation under MSVC 2017 --- include/dissect.h | 4 ++-- include/misc.h | 2 +- include/stick10_commands.h | 10 +++++----- include/stick10_commands_0.8.h | 6 +++--- include/stick20_commands.h | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) (limited to 'include') diff --git a/include/dissect.h b/include/dissect.h index 69a5129..06b99fa 100644 --- a/include/dissect.h +++ b/include/dissect.h @@ -22,7 +22,7 @@ class QueryDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); #endif out << "Contents:" << std::endl; @@ -87,7 +87,7 @@ class ResponseDissector : semantics::non_constructible { #ifdef LOG_VOLATILE_DATA out << "Raw HID packet:" << std::endl; - out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + out << ::nitrokey::misc::hexdump((const uint8_t *)(&pod), sizeof pod); #endif out << "Device status:\t" << pod.device_status + 0 << " " diff --git a/include/misc.h b/include/misc.h index 176b77c..25f3107 100644 --- a/include/misc.h +++ b/include/misc.h @@ -62,7 +62,7 @@ typename T::CommandPayload get_payload(){ CMDTYPE::CommandTransaction::run(stick, p); } - std::string hexdump(const char *p, size_t size, bool print_header=true, bool print_ascii=true, + std::string hexdump(const uint8_t *p, size_t size, bool print_header=true, bool print_ascii=true, bool print_empty=true); uint32_t stm_crc32(const uint8_t *data, size_t size); std::vector hex_string_to_byte(const char* hexString); diff --git a/include/stick10_commands.h b/include/stick10_commands.h index e863328..8f3ceef 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -130,7 +130,7 @@ class WriteToHOTPSlot : Command { ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; ss << std::endl; ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const char *)(&slot_counter), sizeof slot_counter, false); + << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); return ss.str(); } @@ -334,7 +334,7 @@ class ReadSlot : Command { ss << std::hex << std::setw(2) << std::setfill('0')<< (int) i << " " ; ss << std::endl; ss << "slot_counter:\t[" << (int)slot_counter << "]\t" - << ::nitrokey::misc::hexdump((const char *)(&slot_counter), sizeof slot_counter, false); + << ::nitrokey::misc::hexdump((const uint8_t *)(&slot_counter), sizeof slot_counter, false); return ss.str(); } } __packed; @@ -372,13 +372,13 @@ class GetStatus : Command { ss << "firmware_version:\t" << "[" << firmware_version << "]" << "\t" << ::nitrokey::misc::hexdump( - (const char *)(&firmware_version), sizeof firmware_version, false); + (const uint8_t *)(&firmware_version), sizeof firmware_version, false); ss << "card_serial_u32:\t" << std::hex << card_serial_u32 << std::endl; ss << "card_serial:\t" - << ::nitrokey::misc::hexdump((const char *)(card_serial), + << ::nitrokey::misc::hexdump((const uint8_t *)(card_serial), sizeof card_serial, false); ss << "general_config:\t" - << ::nitrokey::misc::hexdump((const char *)(general_config), + << ::nitrokey::misc::hexdump((const uint8_t *)(general_config), sizeof general_config, false); ss << "numlock:\t" << (int)numlock << std::endl; ss << "capslock:\t" << (int)capslock << std::endl; diff --git a/include/stick10_commands_0.8.h b/include/stick10_commands_0.8.h index 4209380..361682d 100644 --- a/include/stick10_commands_0.8.h +++ b/include/stick10_commands_0.8.h @@ -94,7 +94,7 @@ namespace nitrokey { ss << "id:\t" << (int)id << std::endl; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (&data), sizeof data); + << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -113,7 +113,7 @@ namespace nitrokey { std::stringstream ss; #ifdef LOG_VOLATILE_DATA ss << "data:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (&data), sizeof data); + << ::nitrokey::misc::hexdump((const uint8_t *) (&data), sizeof data); #else ss << " Volatile data not logged" << std::endl; #endif @@ -165,7 +165,7 @@ namespace nitrokey { ss << "\tuse_tokenID(2):\t" << use_tokenID << std::endl; ss << "slot_number:\t" << (int) (slot_number) << std::endl; ss << "slot_counter_or_interval:\t[" << (int) slot_counter_or_interval << "]\t" - << ::nitrokey::misc::hexdump((const char *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); + << ::nitrokey::misc::hexdump((const uint8_t *) (&slot_counter_or_interval), sizeof slot_counter_or_interval, false); ss << "slot_token_id:\t"; for (auto i : slot_token_id) diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5f99d28..64df372 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -111,7 +111,7 @@ namespace nitrokey { std::string dissect() const { std::stringstream ss; ss << "_padding:" << std::endl - << ::nitrokey::misc::hexdump((const char *) (_padding), + << ::nitrokey::misc::hexdump((const uint8_t *) (_padding), sizeof _padding); print_to_ss((int) SendCounter_u8); print_to_ss((int) SendDataType_u8); @@ -138,9 +138,9 @@ namespace nitrokey { union{ uint8_t VersionInfo_au8[4]; struct { - uint8_t __reserved; + uint8_t _reserved; uint8_t minor; - uint8_t __reserved2; + uint8_t _reserved2; uint8_t major; } __packed versionInfo; } __packed; -- cgit v1.2.3 From 2da9ee14459d169fd033e36efe8780250b4283b1 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 28 Jun 2017 11:57:21 +0200 Subject: Run compilation using Qt Creator --- NK_C_API.cc | 20 ++++++------- NitrokeyManager.cc | 3 +- include/command.h | 2 +- libnitrokey.pro | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ unittest/test_issues.cc | 4 +-- 5 files changed, 91 insertions(+), 14 deletions(-) create mode 100644 libnitrokey.pro (limited to 'include') diff --git a/NK_C_API.cc b/NK_C_API.cc index db87d90..3131db1 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -5,16 +5,16 @@ #include "include/LibraryException.h" #include "include/cxx_semantics.h" -#ifdef _WIN32 -#pragma message "Using own strndup" -char * strndup(const char* str, size_t maxlen) { - size_t len = strnlen(str, maxlen); - char* dup = (char *)malloc(len + 1); - memcpy(dup, str, len); - dup[len] = 0; - return dup; -} -#endif +//#ifdef _WIN32 +//#pragma message "Using own strndup" +//char * strndup(const char* str, size_t maxlen) { +// size_t len = strnlen(str, maxlen); +// char* dup = (char *)malloc(len + 1); +// memcpy(dup, str, len); +// dup[len] = 0; +// return dup; +//} +//#endif using namespace nitrokey; diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 4393682..4b3c7e1 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -14,6 +14,7 @@ namespace nitrokey{ std::mutex mex_dev_com_manager; +#ifndef strndup #ifdef _WIN32 #pragma message "Using own strndup" char * strndup(const char* str, size_t maxlen){ @@ -24,7 +25,7 @@ char * strndup(const char* str, size_t maxlen){ return dup; } #endif - +#endif using nitrokey::misc::strcpyT; diff --git a/include/command.h b/include/command.h index 3f711c0..279754a 100644 --- a/include/command.h +++ b/include/command.h @@ -11,7 +11,7 @@ #define print_to_ss_volatile(x) ( ss << " " << (#x) <<":\t" << "***********" << std::endl ); #endif #define hexdump_to_ss(x) (ss << #x":\n"\ - << ::nitrokey::misc::hexdump((const char *) (&x), sizeof x, false)); + << ::nitrokey::misc::hexdump((const uint8_t *) (&x), sizeof x, false)); namespace nitrokey { namespace proto { diff --git a/libnitrokey.pro b/libnitrokey.pro new file mode 100644 index 0000000..621a137 --- /dev/null +++ b/libnitrokey.pro @@ -0,0 +1,76 @@ +# Created by and for Qt Creator. This file was created for editing the project sources only. +# You may attempt to use it for building too, by modifying this file here. + +#TARGET = libnitrokey + +CONFIG += c++14 staticlib +#QT = + +TEMPLATE = lib +TARGET = nitrokey + +HEADERS = \ + $$PWD/hidapi/hidapi/hidapi.h \ +# $$PWD/include/hidapi/hidapi.h \ + $$PWD/include/command.h \ + $$PWD/include/command_id.h \ + $$PWD/include/CommandFailedException.h \ + $$PWD/include/cxx_semantics.h \ + $$PWD/include/device.h \ + $$PWD/include/device_proto.h \ + $$PWD/include/DeviceCommunicationExceptions.h \ + $$PWD/include/dissect.h \ + $$PWD/include/inttypes.h \ + $$PWD/include/LibraryException.h \ + $$PWD/include/log.h \ + $$PWD/include/LongOperationInProgressException.h \ + $$PWD/include/misc.h \ + $$PWD/include/NitrokeyManager.h \ + $$PWD/include/stick10_commands.h \ + $$PWD/include/stick10_commands_0.8.h \ + $$PWD/include/stick20_commands.h \ + $$PWD/NK_C_API.h + +SOURCES = \ + $$PWD/command_id.cc \ + $$PWD/device.cc \ + $$PWD/DeviceCommunicationExceptions.cpp \ + $$PWD/log.cc \ + $$PWD/misc.cc \ + $$PWD/NitrokeyManager.cc \ + $$PWD/NK_C_API.cc + + +tests { + SOURCES += \ + $$PWD/unittest/catch_main.cpp \ + $$PWD/unittest/test.cc \ + $$PWD/unittest/test2.cc \ + $$PWD/unittest/test3.cc \ + $$PWD/unittest/test_C_API.cpp \ + $$PWD/unittest/test_HOTP.cc +} + +unix:!macx{ + SOURCES += $$PWD/hidapi/linux/hid.c +} + +unix{ + SOURCES += $$PWD/hidapi/mac/hid.c +} + +#win32 { + SOURCES += $$PWD/hidapi/windows/hid.c + LIBS += -lsetupapi +#} + +INCLUDEPATH = \ + $$PWD/. \ + $$PWD/hidapi/hidapi \ + $$PWD/include \ + $$PWD/include/hidapi \ + $$PWD/unittest \ + $$PWD/unittest/Catch/single_include + +#DEFINES = + diff --git a/unittest/test_issues.cc b/unittest/test_issues.cc index ec3f933..63ce678 100644 --- a/unittest/test_issues.cc +++ b/unittest/test_issues.cc @@ -15,7 +15,7 @@ using namespace nitrokey; bool test_36(){ auto i = NitrokeyManager::instance(); - i->set_debug(true); + i->set_loglevel(3); REQUIRE(i->connect()); for (int j = 0; j < 200; ++j) { @@ -28,7 +28,7 @@ bool test_36(){ bool test_31(){ auto i = NitrokeyManager::instance(); - i->set_debug(true); + i->set_loglevel(3); REQUIRE(i->connect()); // i->unlock_encrypted_volume(default_user_pin); -- cgit v1.2.3