aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/command.h25
-rw-r--r--include/stick20_commands.h78
2 files changed, 29 insertions, 74 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
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<CommandID::SEND_PASSWORD> {
- 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<command_id(), struct CommandPayload, struct EmptyPayload>
- CommandTransaction;
- };
-
-
- class ChangeAdminUserPin20New : Command<CommandID::SEND_NEW_PASSWORD> {
- 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<command_id(), struct CommandPayload, struct EmptyPayload>
- CommandTransaction;
- };
- class UnlockUserPin : Command<CommandID::UNLOCK_USER_PASSWORD> {
- 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<command_id(), struct CommandPayload, struct EmptyPayload>
- CommandTransaction;
- };
+ class ChangeAdminUserPin20Current :
+ public PasswordCommand<CommandID::SEND_PASSWORD, PasswordKind::Admin> {};
+ class ChangeAdminUserPin20New :
+ public PasswordCommand<CommandID::SEND_NEW_PASSWORD, PasswordKind::Admin> {};
+ class UnlockUserPin :
+ public PasswordCommand<CommandID::UNLOCK_USER_PASSWORD, PasswordKind::Admin> {};
class EnableEncryptedPartition : public PasswordCommand<CommandID::ENABLE_CRYPTED_PARI> {};
class DisableEncryptedPartition : public PasswordCommand<CommandID::DISABLE_CRYPTED_PARI> {};