diff options
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r-- | NK_C_API.cc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc index 7de5bbd..c2e7df0 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -1,6 +1,6 @@ #include <cstring> #include "NK_C_API.h" - +#include <functional> using namespace nitrokey; static uint8_t NK_last_command_status = 0; @@ -16,6 +16,18 @@ auto get_with_result(T func){ } } +template <typename T> +uint8_t get_without_result(T func){ + try { + func(); + return 0; + } + 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(){ @@ -245,6 +257,13 @@ extern uint8_t NK_get_admin_retry_count(){ }); } +extern int NK_lock_device(){ + auto m = NitrokeyManager::instance(); + return get_without_result([&](){ + return m->lock_device(); + }); +} + } |