From 547c02f0c5d4195a3efe454b9e98c0d0a84d739c Mon Sep 17 00:00:00 2001 From: Szczepan Zalega Date: Wed, 27 Jul 2016 12:31:08 +0200 Subject: Test read/write config Signed-off-by: Szczepan Zalega --- NK_C_API.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'NK_C_API.cc') diff --git a/NK_C_API.cc b/NK_C_API.cc index e5febe1..d93fafc 100644 --- a/NK_C_API.cc +++ b/NK_C_API.cc @@ -4,6 +4,24 @@ using namespace nitrokey; static uint8_t NK_last_command_status = 0; +template +T* array_dup(std::vector& v){ + auto d = new T[v.size()]; + std::copy(v.begin(), v.end(), d); + return d; +} + +template +uint8_t * get_with_array_result(T func){ + try { + return func(); + } + catch (CommandFailedException & commandFailedException){ + NK_last_command_status = commandFailedException.last_command_status; + return nullptr; + } +} + template const char* get_with_string_result(T func){ try { @@ -114,6 +132,16 @@ extern int NK_write_config(bool numlock, bool capslock, bool scrolllock, bool en }); } + +extern uint8_t* NK_read_config(){ + auto m = NitrokeyManager::instance(); + return get_with_array_result( [&](){ + auto v = m->read_config(); + return array_dup(v); + }); +} + + extern const char * NK_status() { auto m = NitrokeyManager::instance(); try { -- cgit v1.2.1