aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt7
-rw-r--r--NK_C_API.cc11
-rw-r--r--NitrokeyManager.cc2
-rw-r--r--include/dissect.h4
-rw-r--r--include/misc.h2
-rw-r--r--include/stick10_commands.h10
-rw-r--r--include/stick10_commands_0.8.h6
-rw-r--r--include/stick20_commands.h6
-rw-r--r--misc.cc14
9 files changed, 39 insertions, 23 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6741b18..11882f9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,3 +1,8 @@
+# https://cmake.org/pipermail/cmake/2011-May/044166.html
+ IF(NOT DEFINED CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS)
+ SET(CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_NO_WARNINGS ON)
+ ENDIF()
+
cmake_minimum_required(VERSION 3.1)
IF (UNIX)
OPTION(USE_CLANG "Use CLang" FALSE)
@@ -111,7 +116,7 @@ install (FILES ${LIB_INCLUDES} DESTINATION "include")
IF (COMPILE_TESTS)
include_directories(unittest/Catch/include)
- add_library(catch SHARED unittest/catch_main.cpp )
+ add_library(catch STATIC unittest/catch_main.cpp )
add_executable (test_C_API unittest/test_C_API.cpp)
target_link_libraries (test_C_API ${EXTRA_LIBS} ${LIBNAME}-log catch)
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 0e3fa1f..db87d90 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -5,6 +5,17 @@
#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
+
using namespace nitrokey;
static uint8_t NK_last_command_status = 0;
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 9a9d106..4393682 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -14,7 +14,7 @@ namespace nitrokey{
std::mutex mex_dev_com_manager;
-#ifdef __WIN32
+#ifdef _WIN32
#pragma message "Using own strndup"
char * strndup(const char* str, size_t maxlen){
size_t len = strnlen(str, maxlen);
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<uint8_t> 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<CommandID::WRITE_TO_SLOT> {
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<CommandID::READ_SLOT> {
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<CommandID::GET_STATUS> {
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;
diff --git a/misc.cc b/misc.cc
index 24f8514..d7278da 100644
--- a/misc.cc
+++ b/misc.cc
@@ -39,20 +39,20 @@ namespace misc {
};
#include <cctype>
-::std::string hexdump(const char *p, size_t size, bool print_header,
+::std::string hexdump(const uint8_t *p, size_t size, bool print_header,
bool print_ascii, bool print_empty) {
::std::stringstream out;
char formatbuf[128];
- const char *pstart = p;
+ const uint8_t *pstart = p;
- for (const char *pend = p + size; p < pend;) {
+ for (const uint8_t *pend = p + size; p < pend;) {
if (print_header){
snprintf(formatbuf, 128, "%04x\t", static_cast<int> (p - pstart));
out << formatbuf;
}
- const char* pp = p;
- for (const char *le = p + 16; p < le; p++) {
+ const uint8_t* pp = p;
+ for (const uint8_t *le = p + 16; p < le; p++) {
if (p < pend){
snprintf(formatbuf, 128, "%02x ", uint8_t(*p));
out << formatbuf;
@@ -63,8 +63,8 @@ namespace misc {
}
if(print_ascii){
- out << "\t";
- for (const char *le = pp + 16; pp < le && pp < pend; pp++) {
+ out << " ";
+ for (const uint8_t *le = pp + 16; pp < le && pp < pend; pp++) {
if (std::isgraph(*pp))
out << uint8_t(*pp);
else