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(-) (limited to 'include/command.h') 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.1 From 9a56e6c27104ead60a89c403e77494bfcfea563f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 14:52:10 +0200 Subject: Remove static keyword from CommandID dissection Signed-off-by: Szczepan Zalega --- include/command.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/command.h') diff --git a/include/command.h b/include/command.h index 7f723e5..6e3525e 100644 --- a/include/command.h +++ b/include/command.h @@ -13,7 +13,7 @@ namespace nitrokey { constexpr static CommandID command_id() { return cmd_id; } template - static std::string dissect(const T &) { + std::string dissect(const T &) { return std::string("Payload dissection is unavailable"); } }; -- cgit v1.2.1 From 33a2d790e0a68d243bc1d9e9f75590b141d85c7f Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 24 Oct 2016 16:19:00 +0200 Subject: Fix printing macro Signed-off-by: Szczepan Zalega --- include/command.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include/command.h') diff --git a/include/command.h b/include/command.h index 6e3525e..5ac1d7f 100644 --- a/include/command.h +++ b/include/command.h @@ -18,7 +18,7 @@ namespace nitrokey { } }; -#define print_to_ss(x) ( ss << " #x:\t" << (x) << std::endl ); +#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); template class PasswordCommand : public Command { @@ -48,5 +48,6 @@ namespace nitrokey { }; } } +#undef print_to_ss #endif -- cgit v1.2.1 From 9ad4796130a4ce192420563bb601468ffc292df9 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 17:48:18 +0100 Subject: Code refactoring - unify password only commands Signed-off-by: Szczepan Zalega --- include/command.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'include/command.h') diff --git a/include/command.h b/include/command.h index 5ac1d7f..badf068 100644 --- a/include/command.h +++ b/include/command.h @@ -19,13 +19,18 @@ namespace nitrokey { }; #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); +namespace stick20{ + enum class PasswordKind : uint8_t { + User = 'P', + Admin = 'A' + }; - template + template class PasswordCommand : public Command { public: struct CommandPayload { uint8_t kind; - uint8_t password[20]; + uint8_t password[password_length]; std::string dissect() const { std::stringstream ss; @@ -40,6 +45,21 @@ namespace nitrokey { kind = (uint8_t) 'P'; } + void set_defaults(){ + set_kind(Tpassword_kind); + } + + void set_kind(PasswordKind password_kind){ + switch (password_kind){ + case PasswordKind::Admin: + set_kind_admin(); + break; + case PasswordKind::User: + set_kind_user(); + break; + } + }; + } __packed; typedef Transaction::command_id(), struct CommandPayload, struct EmptyPayload> @@ -47,6 +67,7 @@ namespace nitrokey { }; } + } } #undef print_to_ss -- cgit v1.2.1 From 98b27cb58b12f699b5c11f88d55c3e3f70ed2063 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Mon, 31 Oct 2016 18:02:55 +0100 Subject: Code refactoring - unify password only commands (2) Signed-off-by: Szczepan Zalega --- include/command.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'include/command.h') diff --git a/include/command.h b/include/command.h index badf068..0a875e4 100644 --- a/include/command.h +++ b/include/command.h @@ -22,7 +22,8 @@ namespace nitrokey { namespace stick20{ enum class PasswordKind : uint8_t { User = 'P', - Admin = 'A' + Admin = 'A', + AdminPrefixed }; template @@ -41,6 +42,9 @@ namespace stick20{ void set_kind_admin() { kind = (uint8_t) 'A'; } + void set_kind_admin_prefixed() { + kind = (uint8_t) 'P'; + } void set_kind_user() { kind = (uint8_t) 'P'; } @@ -57,6 +61,9 @@ namespace stick20{ case PasswordKind::User: set_kind_user(); break; + case PasswordKind::AdminPrefixed: + set_kind_admin_prefixed(); + break; } }; -- cgit v1.2.1