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 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'NitrokeyManager.cc') 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; } -- cgit v1.2.1