aboutsummaryrefslogtreecommitdiff
path: root/NK_C_API.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-08-09 13:25:19 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-08-09 18:34:00 +0200
commitbcfc7f44632717855ed75a3e643278a3ddee7309 (patch)
treebadc4598f7fe5e42c37d214cc212563b12505992 /NK_C_API.cc
parent95a4b415b76ff94cd270dcc3c6a53efd8b152914 (diff)
downloadlibnitrokey-bcfc7f44632717855ed75a3e643278a3ddee7309.tar.gz
libnitrokey-bcfc7f44632717855ed75a3e643278a3ddee7309.tar.bz2
Return a vector to C API to duplicate there
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, 8 insertions, 13 deletions
diff --git a/NK_C_API.cc b/NK_C_API.cc
index 556ec65..577f2d6 100644
--- a/NK_C_API.cc
+++ b/NK_C_API.cc
@@ -5,9 +5,10 @@ using namespace nitrokey;
static uint8_t NK_last_command_status = 0;
template <typename T>
-T* array_dup(std::vector<T>& v){
+T* duplicate_vector_and_clear(std::vector<T> &v){
auto d = new T[v.size()];
std::copy(v.begin(), v.end(), d);
+ std::fill(v.begin(), v.end(), 0);
return d;
}
@@ -141,7 +142,7 @@ extern uint8_t* NK_read_config(){
auto m = NitrokeyManager::instance();
return get_with_array_result( [&](){
auto v = m->read_config();
- return array_dup(v);
+ return duplicate_vector_and_clear(v);
});
}
@@ -274,18 +275,12 @@ extern int NK_enable_password_safe(const char *user_pin){
});
}
extern uint8_t * NK_get_password_safe_slot_status(){
- NK_last_command_status = 0;
auto m = NitrokeyManager::instance();
- auto null_result = new uint8_t[16];
- memset(null_result, 0, 16);
- try {
- const auto slot_status = m->get_password_safe_slot_status();
- return slot_status; //TODO FIXME
- }
- catch (CommandFailedException & commandFailedException){
- NK_last_command_status = commandFailedException.last_command_status;
- }
- return null_result;
+ return get_with_array_result( [&](){
+ auto slot_status = m->get_password_safe_slot_status();
+ return duplicate_vector_and_clear(slot_status);
+ });
+
}
extern uint8_t NK_get_user_retry_count(){