aboutsummaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-07-26 12:23:26 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-01 13:54:57 +0200
commit32ed4100e098ae2930e6fd94800c6ce7041101c2 (patch)
tree5cd408f732d1b40ec1651dbcae35ffa0f4501206 /NK_C_API.cc
parent39b7c99bbd00c0bc4906939ceefb724a3d9ddc35 (diff)
downloadlibnitrokey-32ed4100e098ae2930e6fd94800c6ce7041101c2.tar.gz
libnitrokey-32ed4100e098ae2930e6fd94800c6ce7041101c2.tar.bz2
Working PW safe getting slot name
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NK_C_API.cc')
-rw-r--r--NK_C_API.cc36
1 files changed, 35 insertions, 1 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index c2e7df0..f01f0f5 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -1,11 +1,21 @@
#include <cstring>
#include "NK_C_API.h"
-#include <functional>
using namespace nitrokey;
static uint8_t NK_last_command_status = 0;
template <typename T>
+const char* get_with_string_result(T func){
+ try {
+ return func();
+ }
+ catch (CommandFailedException & commandFailedException){
+ NK_last_command_status = commandFailedException.last_command_status;
+ return "";
+ }
+}
+
+template <typename T>
auto get_with_result(T func){
try {
return func();
@@ -264,6 +274,30 @@ extern int NK_lock_device(){
});
}
+extern const char *NK_get_password_safe_slot_name(uint8_t slot_number, const char *temporary_password) {
+ auto m = NitrokeyManager::instance();
+ return get_with_string_result([&](){
+ return m->get_password_safe_slot_name(slot_number, temporary_password);
+ });
+}
+
+extern const char *NK_get_password_safe_slot_login(uint8_t slot_number) {
+ auto m = NitrokeyManager::instance();
+ return get_with_string_result([&](){
+ return m->get_password_safe_slot_login(slot_number);
+ });
+}
+extern const char *NK_get_password_safe_slot_password(uint8_t slot_number) {
+ auto m = NitrokeyManager::instance();
+ return get_with_string_result([&](){
+ return m->get_password_safe_slot_password(slot_number);
+ });
+}
+extern int NK_write_password_safe_slot(){
+ auto m = NitrokeyManager::instance();
+ //TODO
+}
+
}