From adbc664125142c434294bfa795666c90c7608429 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Thu, 9 Mar 2017 18:49:24 +0100 Subject: Adjust for compilation on Visual Studio 2017 Building works however tests are not. Possibly linking with original hidapi solution would work. --- include/LibraryException.h | 2 +- include/command.h | 7 +++++-- include/cxx_semantics.h | 4 ++++ include/device_proto.h | 8 +++++--- include/misc.h | 2 +- include/stick10_commands.h | 8 ++++++++ include/stick20_commands.h | 5 +++++ 7 files changed, 29 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/include/LibraryException.h b/include/LibraryException.h index e62788d..daf0155 100644 --- a/include/LibraryException.h +++ b/include/LibraryException.h @@ -27,7 +27,7 @@ public: virtual const char *what() const throw() override { std::string s = " "; - auto ts = [](int x){ return std::to_string(x); }; + auto ts = [](size_t x){ return std::to_string(x); }; std::string msg = std::string("Target buffer size is smaller than source: [source size, buffer size]") +s+ ts(source_size) +s+ ts(target_size); return msg.c_str(); diff --git a/include/command.h b/include/command.h index 0a875e4..fc374f7 100644 --- a/include/command.h +++ b/include/command.h @@ -28,6 +28,7 @@ namespace stick20{ template class PasswordCommand : public Command { + constexpr static CommandID _command_id() { return cmd_id; } public: struct CommandPayload { uint8_t kind; @@ -69,8 +70,10 @@ namespace stick20{ } __packed; - typedef Transaction::command_id(), struct CommandPayload, struct EmptyPayload> - CommandTransaction; + //typedef Transaction::command_id(), struct CommandPayload, struct EmptyPayload> + // CommandTransaction; + using CommandTransaction = Transaction; + //using CommandTransaction = Transaction<_command_id(), CommandPayload, EmptyPayload>; }; } diff --git a/include/cxx_semantics.h b/include/cxx_semantics.h index b846317..29e51c3 100644 --- a/include/cxx_semantics.h +++ b/include/cxx_semantics.h @@ -1,7 +1,11 @@ #ifndef CXX_SEMANTICS_H #define CXX_SEMANTICS_H +#ifndef _WINDOWS #define __packed __attribute__((__packed__)) +#else +#define __packed +#endif /* * There's no need to include Boost for a simple subset this project needs. diff --git a/include/device_proto.h b/include/device_proto.h index cbb74fb..1e381dd 100644 --- a/include/device_proto.h +++ b/include/device_proto.h @@ -6,7 +6,6 @@ #include #include #include -#include // a local version for compatibility with Windows #include #include "cxx_semantics.h" @@ -34,6 +33,7 @@ #include #include "DeviceCommunicationExceptions.h" +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) namespace nitrokey { namespace proto { @@ -43,7 +43,7 @@ namespace nitrokey { * * TODO (future) support for Big Endian */ - +#pragma pack (push,1) /* * Every packet is a USB HID report (check USB spec) */ @@ -181,8 +181,10 @@ namespace nitrokey { typedef command_payload CommandPayload; typedef response_payload ResponsePayload; + typedef struct HIDReport OutgoingPacket; typedef struct DeviceResponse ResponsePacket; +#pragma pack (pop) static_assert(std::is_pod::value, "outgoingpacket must be a pod type"); @@ -216,7 +218,7 @@ namespace nitrokey { static std::mutex send_receive_mtx; std::lock_guard guard(send_receive_mtx); - Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); + Log::instance()(__FUNCTION__, Loglevel::DEBUG_L2); if (dev == nullptr){ throw DeviceNotConnected("Device not initialized"); diff --git a/include/misc.h b/include/misc.h index 9e4659d..330654a 100644 --- a/include/misc.h +++ b/include/misc.h @@ -27,7 +27,7 @@ namespace misc { strncpy((char*) &dest, src, s_dest); } - +#define bzero(b,len) (memset((b), '\0', (len)), (void) 0) template typename T::CommandPayload get_payload(){ //Create, initialize and return by value command payload diff --git a/include/stick10_commands.h b/include/stick10_commands.h index 8d37dbd..3d9e234 100644 --- a/include/stick10_commands.h +++ b/include/stick10_commands.h @@ -1,5 +1,6 @@ #ifndef STICK10_COMMANDS_H #define STICK10_COMMANDS_H + #include #include #include @@ -8,9 +9,13 @@ #include "command.h" #include "device_proto.h" +#pragma pack (push,1) + namespace nitrokey { namespace proto { + + /* * Stick10 protocol definition */ @@ -844,8 +849,11 @@ class BuildAESKey : Command { typedef Transaction CommandTransaction; + }; + } } } +#pragma pack (pop) #endif diff --git a/include/stick20_commands.h b/include/stick20_commands.h index b887636..e3bea3f 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -1,12 +1,15 @@ #ifndef STICK20_COMMANDS_H #define STICK20_COMMANDS_H + + #include #include "command.h" #include #include #include "device_proto.h" +#pragma pack (push,1) namespace nitrokey { namespace proto { @@ -332,10 +335,12 @@ namespace nitrokey { typedef Transaction CommandTransaction; }; + } } } #undef print_to_ss +#pragma pack (pop) #endif -- cgit v1.2.3