From 3a856bcfaac6490426f03f0ac149ef5445c5c36f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Sat, 22 Oct 2016 18:59:30 +0200 Subject: General password based command Signed-off-by: Szczepan Zalega --- include/command.h | 55 ++++++++++++++++++++++++++++++++++++++++++------------- 1 file 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 -class Command : semantics::non_constructible { - public: - constexpr static CommandID command_id() { return cmd_id; } - - template - static std::string dissect(const T &) { - return std::string("Payload dissection is unavailable"); - } -}; -} + namespace proto { + + template + class Command : semantics::non_constructible { + public: + constexpr static CommandID command_id() { return cmd_id; } + + template + 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 + class PasswordCommand : public Command { + 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_id(), struct CommandPayload, struct EmptyPayload> + CommandTransaction; + + }; + } } #endif -- cgit v1.2.3