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/stick20_commands.h | 78 ++++------------------------------------------ 1 file changed, 6 insertions(+), 72 deletions(-) (limited to 'include/stick20_commands.h') diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 5c2d97e..a51d1ca 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -18,80 +18,14 @@ namespace nitrokey { #define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl ); namespace stick20 { - enum class PasswordKind : uint8_t { - User = 'P', - Admin = 'A' - }; - - class ChangeAdminUserPin20Current : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t old_pin[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " old_pin:\t" << old_pin << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; - - - class ChangeAdminUserPin20New : Command { - public: - - struct CommandPayload { - uint8_t kind; - uint8_t new_pin[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " new_pin:\t" << new_pin << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - - } __packed; - - typedef Transaction - CommandTransaction; - }; - class UnlockUserPin : Command { - public: - struct CommandPayload { - uint8_t kind; - uint8_t user_new_password[20]; - - std::string dissect() const { - std::stringstream ss; - print_to_ss( kind ); - ss << " user_new_password:\t" << user_new_password << std::endl; - return ss.str(); - } - - void set_kind(PasswordKind k) { - kind = (uint8_t) k; - } - } __packed; - - typedef Transaction - CommandTransaction; - }; + class ChangeAdminUserPin20Current : + public PasswordCommand {}; + class ChangeAdminUserPin20New : + public PasswordCommand {}; + class UnlockUserPin : + public PasswordCommand {}; class EnableEncryptedPartition : public PasswordCommand {}; class DisableEncryptedPartition : public PasswordCommand {}; -- cgit v1.2.1