From 39b7c99bbd00c0bc4906939ceefb724a3d9ddc35 Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Tue, 26 Jul 2016 11:36:04 +0200 Subject: Handle locking device Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'NK_C_API.cc') 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 #include "NK_C_API.h" - +#include using namespace nitrokey; static uint8_t NK_last_command_status = 0; @@ -16,6 +16,18 @@ auto get_with_result(T func){ } } +template +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(); + }); +} + } -- cgit v1.2.1