aboutsummaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-29 15:15:35 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:58 +0200
commit0038f840f8279483e4a8fcb9edf800425fdb9fec (patch)
tree0a15b30ae8cf8f925ef67b310aa4aecd26e06362 /NitrokeyManager.cc
parent5cd264c294ca6f1bf0758bb5fb0b51f3584d2795 (diff)
downloadlibnitrokey-0038f840f8279483e4a8fcb9edf800425fdb9fec.tar.gz
libnitrokey-0038f840f8279483e4a8fcb9edf800425fdb9fec.tar.bz2
Merge changing PIN functions
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc31
1 files changed, 16 insertions, 15 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<ChangeUserPin>();
- strcpyT(p.old_pin, current_PIN);
- strcpyT(p.new_pin, new_PIN);
- ChangeUserPin::CommandTransaction::run(*device, p);
+ change_PIN_general<ChangeUserPin, PasswordKind::User>(current_PIN, new_PIN);
}
+
void NitrokeyManager::change_admin_PIN(char *current_PIN, char *new_PIN) {
+ change_PIN_general<ChangeAdminPin, PasswordKind::Admin>(current_PIN, new_PIN);
+ }
+
+ template <typename ProCommand, PasswordKind StoKind>
+ void NitrokeyManager::change_PIN_general(char *current_PIN, char *new_PIN) {
switch (device->get_device_model()){
case DeviceModel::PRO:
{
- auto p = get_payload<ChangeAdminPin>();
+ auto p = get_payload<ProCommand>();
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<ChangeAdminPin20Current>();
+ auto p = get_payload<ChangeAdminUserPin20Current>();
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<ChangeAdminPin20New>();
+ auto p2 = get_payload<ChangeAdminUserPin20New>();
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;
}