summaryrefslogtreecommitdiff
path: root/include/command.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-22 18:59:30 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 15:54:12 +0100
commit3a856bcfaac6490426f03f0ac149ef5445c5c36f (patch)
tree7ed19b930bf59730831101dc1daffb8e1b818864 /include/command.h
parentb0e14aeb25e8d5d799b685bdc844b87617d97c80 (diff)
downloadlibnitrokey-3a856bcfaac6490426f03f0ac149ef5445c5c36f.tar.gz
libnitrokey-3a856bcfaac6490426f03f0ac149ef5445c5c36f.tar.bz2
General password based command
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/command.h')
-rw-r--r--include/command.h55
1 files changed, 42 insertions, 13 deletions
diff --git a/include/command.h b/include/command.h
index 715902d..7f723e5 100644
--- a/include/command.h
+++ b/include/command.h
@@ -5,19 +5,48 @@
#include "cxx_semantics.h"
namespace nitrokey {
-namespace proto {
-
-template <CommandID cmd_id>
-class Command : semantics::non_constructible {
- public:
- constexpr static CommandID command_id() { return cmd_id; }
-
- template <typename T>
- static std::string dissect(const T &) {
- return std::string("Payload dissection is unavailable");
- }
-};
-}
+ namespace proto {
+
+ template<CommandID cmd_id>
+ class Command : semantics::non_constructible {
+ public:
+ constexpr static CommandID command_id() { return cmd_id; }
+
+ template<typename T>
+ static std::string dissect(const T &) {
+ return std::string("Payload dissection is unavailable");
+ }
+ };
+
+#define print_to_ss(x) ( ss << " #x:\t" << (x) << std::endl );
+
+ template<CommandID cmd_id>
+ class PasswordCommand : public Command<cmd_id> {
+ public:
+ struct CommandPayload {
+ uint8_t kind;
+ uint8_t password[20];
+
+ std::string dissect() const {
+ std::stringstream ss;
+ print_to_ss( kind );
+ print_to_ss(password);
+ return ss.str();
+ }
+ void set_kind_admin() {
+ kind = (uint8_t) 'A';
+ }
+ void set_kind_user() {
+ kind = (uint8_t) 'P';
+ }
+
+ } __packed;
+
+ typedef Transaction<Command<cmd_id>::command_id(), struct CommandPayload, struct EmptyPayload>
+ CommandTransaction;
+
+ };
+ }
}
#endif