summaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-27 12:31:08 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit547c02f0c5d4195a3efe454b9e98c0d0a84d739c (patch)
tree567ba270839328cc8fe6444a8dca130bd30d20be /NK_C_API.cc
parentd26f8fc73e2a15314c44688e372f9d4613dcfdd8 (diff)
downloadlibnitrokey-547c02f0c5d4195a3efe454b9e98c0d0a84d739c.tar.gz
libnitrokey-547c02f0c5d4195a3efe454b9e98c0d0a84d739c.tar.bz2
Test read/write config
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc28
1 files changed, 28 insertions, 0 deletions
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
@@ -5,6 +5,24 @@ using namespace nitrokey;
static uint8_t NK_last_command_status = 0;
template <typename T>
+T* array_dup(std::vector<T>& v){
+ auto d = new T[v.size()];
+ std::copy(v.begin(), v.end(), d);
+ return d;
+}
+
+template <typename T>
+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 <typename T>
const char* get_with_string_result(T func){
try {
return func();
@@ -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 {