aboutsummaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-26 11:36:04 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit39b7c99bbd00c0bc4906939ceefb724a3d9ddc35 (patch)
tree16e13a656aeeccb1b14193c33e8728462d32c8d0 /NK_C_API.cc
parent8a938be4ffa97490d89206cc1fd079a057cfc65c (diff)
downloadlibnitrokey-39b7c99bbd00c0bc4906939ceefb724a3d9ddc35.tar.gz
libnitrokey-39b7c99bbd00c0bc4906939ceefb724a3d9ddc35.tar.bz2
Handle locking device
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc21
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();
+ });
+}
+
}