aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/LibraryException.h2
-rw-r--r--include/command.h7
-rw-r--r--include/cxx_semantics.h4
-rw-r--r--include/device_proto.h8
-rw-r--r--include/misc.h2
-rw-r--r--include/stick10_commands.h8
-rw-r--r--include/stick20_commands.h5
7 files changed, 29 insertions, 7 deletions
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<CommandID cmd_id, PasswordKind Tpassword_kind = PasswordKind::User, int password_length = 20>
class PasswordCommand : public Command<cmd_id> {
+ constexpr static CommandID _command_id() { return cmd_id; }
public:
struct CommandPayload {
uint8_t kind;
@@ -69,8 +70,10 @@ namespace stick20{
} __packed;
- typedef Transaction<Command<cmd_id>::command_id(), struct CommandPayload, struct EmptyPayload>
- CommandTransaction;
+ //typedef Transaction<Command<cmd_id>::command_id(), struct CommandPayload, struct EmptyPayload>
+ // CommandTransaction;
+ using CommandTransaction = Transaction<cmd_id, CommandPayload, EmptyPayload>;
+ //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 <type_traits>
#include <stdexcept>
#include <string>
-#include <strings.h>
// a local version for compatibility with Windows
#include <stdint.h>
#include "cxx_semantics.h"
@@ -34,6 +33,7 @@
#include <mutex>
#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<cmd_id, CommandPayload> OutgoingPacket;
typedef struct DeviceResponse<cmd_id, ResponsePayload> ResponsePacket;
+#pragma pack (pop)
static_assert(std::is_pod<OutgoingPacket>::value,
"outgoingpacket must be a pod type");
@@ -216,7 +218,7 @@ namespace nitrokey {
static std::mutex send_receive_mtx;
std::lock_guard<std::mutex> 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>
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 <bitset>
#include <iomanip>
#include <string>
@@ -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<CommandID::NEW_AES_KEY> {
typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
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 <stdint.h>
#include "command.h"
#include <string>
#include <sstream>
#include "device_proto.h"
+#pragma pack (push,1)
namespace nitrokey {
namespace proto {
@@ -332,10 +335,12 @@ namespace nitrokey {
typedef Transaction<command_id(), struct EmptyPayload, struct ResponsePayload>
CommandTransaction;
};
+
}
}
}
#undef print_to_ss
+#pragma pack (pop)
#endif