From 0038f840f8279483e4a8fcb9edf800425fdb9fec Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Fri, 29 Jul 2016 15:15:35 +0200 Subject: Merge changing PIN functions Signed-off-by: Szczepan Zalega --- NitrokeyManager.cc | 31 ++++++++++++++++--------------- include/NitrokeyManager.h | 2 ++ include/stick20_commands.h | 4 ++-- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc index 7f7a870..fc1daa5 100644 --- a/NitrokeyManager.cc +++ b/NitrokeyManager.cc @@ -233,35 +233,36 @@ namespace nitrokey{ } void NitrokeyManager::change_user_PIN(char *current_PIN, char *new_PIN) { - auto p = get_payload(); - strcpyT(p.old_pin, current_PIN); - strcpyT(p.new_pin, new_PIN); - ChangeUserPin::CommandTransaction::run(*device, p); + change_PIN_general(current_PIN, new_PIN); } + void NitrokeyManager::change_admin_PIN(char *current_PIN, char *new_PIN) { + change_PIN_general(current_PIN, new_PIN); + } + + template + void NitrokeyManager::change_PIN_general(char *current_PIN, char *new_PIN) { switch (device->get_device_model()){ case DeviceModel::PRO: { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.old_pin, current_PIN); strcpyT(p.new_pin, new_PIN); - ChangeAdminPin::CommandTransaction::run(*device, p); + ProCommand::CommandTransaction::run(*device, p); } break; - //in Storage change admin pin is divided to two commands with 20 chars field len + //in Storage change admin/user pin is divided to two commands with 20 chars field len case DeviceModel::STORAGE: { - auto p = get_payload(); + auto p = get_payload(); strcpyT(p.old_pin, current_PIN); - p.kind = 'A'; - p.set_kind(PasswordKind::Admin); - ChangeAdminPin20Current::CommandTransaction::run(*device, p); + p.set_kind(StoKind); + ChangeAdminUserPin20Current::CommandTransaction::run(*device, p); - auto p2 = get_payload(); + auto p2 = get_payload(); strcpyT(p2.new_pin, new_PIN); - p2.kind = 'A'; - p2.set_kind(PasswordKind::Admin); - ChangeAdminPin20New::CommandTransaction::run(*device, p2); + p2.set_kind(StoKind); + ChangeAdminUserPin20New::CommandTransaction::run(*device, p2); } break; } diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h index fdb485f..4f1dcfa 100644 --- a/include/NitrokeyManager.h +++ b/include/NitrokeyManager.h @@ -91,6 +91,8 @@ namespace nitrokey { bool erase_slot(uint8_t slot_number, const char *temporary_password); uint8_t *get_slot_name(uint8_t slot_number) const; + template + void change_PIN_general(char *current_PIN, char *new_PIN); }; } diff --git a/include/stick20_commands.h b/include/stick20_commands.h index 66fad15..ec1b088 100644 --- a/include/stick20_commands.h +++ b/include/stick20_commands.h @@ -21,7 +21,7 @@ namespace stick20 { Admin = 'A' }; - class ChangeAdminPin20Current : Command { + class ChangeAdminUserPin20Current : Command { public: struct CommandPayload { uint8_t kind; @@ -41,7 +41,7 @@ namespace stick20 { }; - class ChangeAdminPin20New : Command { + class ChangeAdminUserPin20New : Command { public: struct CommandPayload { -- cgit v1.2.1