aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-31 18:02:55 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:27 +0100
commit98b27cb58b12f699b5c11f88d55c3e3f70ed2063 (patch)
treeae44353f68c1aa02cf305b53e67321d468e39a52
parent9ad4796130a4ce192420563bb601468ffc292df9 (diff)
downloadlibnitrokey-98b27cb58b12f699b5c11f88d55c3e3f70ed2063.tar.gz
libnitrokey-98b27cb58b12f699b5c11f88d55c3e3f70ed2063.tar.bz2
Code refactoring - unify password only commands (2)
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NitrokeyManager.cc4
-rw-r--r--include/command.h9
-rw-r--r--include/stick20_commands.h24
3 files changed, 12 insertions, 25 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index eb34ef2..f0099da 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -420,8 +420,8 @@ namespace nitrokey{
}
case DeviceModel::STORAGE : {
auto p = get_payload<stick20::CreateNewKeys>();
- strcpyT(p.admin_pin, admin_password);
- p.setKindPrefixed();
+ strcpyT(p.password, admin_password);
+ p.set_defaults();
stick20::CreateNewKeys::CommandTransaction::run(*device, p);
break;
}
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<CommandID cmd_id, PasswordKind Tpassword_kind = PasswordKind::User, int password_length = 20>
@@ -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;
}
};
diff --git a/include/stick20_commands.h b/include/stick20_commands.h
index a51d1ca..d7d89cf 100644
--- a/include/stick20_commands.h
+++ b/include/stick20_commands.h
@@ -18,8 +18,6 @@ namespace nitrokey {
#define print_to_ss(x) ( ss << " " << (#x) <<":\t" << (x) << std::endl );
namespace stick20 {
-
-
class ChangeAdminUserPin20Current :
public PasswordCommand<CommandID::SEND_PASSWORD, PasswordKind::Admin> {};
class ChangeAdminUserPin20New :
@@ -54,26 +52,8 @@ namespace nitrokey {
class ExportFirmware : public PasswordCommand<CommandID::EXPORT_FIRMWARE_TO_FILE> {};
- class CreateNewKeys : Command<CommandID::GENERATE_NEW_KEYS> {
- public:
- struct CommandPayload {
- uint8_t kind;
- uint8_t admin_pin[30]; //CS20_MAX_PASSWORD_LEN
- std::string dissect() const {
- std::stringstream ss;
- print_to_ss( kind );
- ss << " admin_pin:\t" << admin_pin << std::endl;
- return ss.str();
- }
-
- void setKindPrefixed() {
- kind = 'P';
- }
- } __packed;
-
- typedef Transaction<command_id(), struct CommandPayload, struct EmptyPayload>
- CommandTransaction;
- };
+ class CreateNewKeys :
+ public PasswordCommand<CommandID::GENERATE_NEW_KEYS, PasswordKind::AdminPrefixed, 30> {};
class FillSDCardWithRandomChars : Command<CommandID::FILL_SD_CARD_WITH_RANDOM_CHARS> {