From 8a938be4ffa97490d89206cc1fd079a057cfc65c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 26 Jul 2016 10:59:24 +0200 Subject: Manage retry counts of user and admin passwords Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'NK_C_API.cc') diff --git a/NK_C_API.cc b/NK_C_API.cc index 77bd181..7de5bbd 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -5,6 +5,17 @@ using namespace nitrokey; static uint8_t NK_last_command_status = 0; +template +auto get_with_result(T func){ + try { + return func(); + } + catch (CommandFailedException & commandFailedException){ + NK_last_command_status = commandFailedException.last_command_status; + return commandFailedException.last_command_status; + } +} + extern "C" { extern uint8_t NK_get_last_command_status(){ @@ -211,7 +222,7 @@ extern int NK_enable_password_safe(const char *user_pin){ extern int NK_get_password_safe_slot_status(){ auto m = NitrokeyManager::instance(); try { - m->get_password_safe_slot_status(); + m->get_password_safe_slot_status(); //TODO FIXME } catch (CommandFailedException & commandFailedException){ NK_last_command_status = commandFailedException.last_command_status; @@ -220,4 +231,20 @@ extern int NK_get_password_safe_slot_status(){ return 0; } -} \ No newline at end of file +extern uint8_t NK_get_user_retry_count(){ + auto m = NitrokeyManager::instance(); + return get_with_result([&](){ + return m->get_user_retry_count(); + }); +} + +extern uint8_t NK_get_admin_retry_count(){ + auto m = NitrokeyManager::instance(); + return get_with_result([&](){ + return m->get_admin_retry_count(); + }); +} + + +} + -- cgit v1.2.1