aboutsummaryrefslogtreecommitdiff
path: root/include/command.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-31 17:48:18 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:27 +0100
commit9ad4796130a4ce192420563bb601468ffc292df9 (patch)
treec72fa01b9255a014ccef1551e91eaffadbd7c05d /include/command.h
parent8b49ee9e25efbca9d0d51fcc8be17fd115fc78fd (diff)
downloadlibnitrokey-9ad4796130a4ce192420563bb601468ffc292df9.tar.gz
libnitrokey-9ad4796130a4ce192420563bb601468ffc292df9.tar.bz2
Code refactoring - unify password only commands
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/command.h')
-rw-r--r--include/command.h25
1 files changed, 23 insertions, 2 deletions
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<CommandID cmd_id>
+ template<CommandID cmd_id, PasswordKind Tpassword_kind = PasswordKind::User, int password_length = 20>
class PasswordCommand : public Command<cmd_id> {
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<cmd_id>::command_id(), struct CommandPayload, struct EmptyPayload>
@@ -47,6 +67,7 @@ namespace nitrokey {
};
}
+ }
}
#undef print_to_ss