aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NK_C_API.cc21
-rw-r--r--NitrokeyManager.cc12
-rw-r--r--include/NitrokeyManager.h2
3 files changed, 15 insertions, 20 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(){
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index 14e31b2..4b7f591 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -282,12 +282,12 @@ namespace nitrokey{
EnablePasswordSafe::CommandTransaction::run(*device, p);
}
- uint8_t * NitrokeyManager::get_password_safe_slot_status() {
- auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(*device); //TODO FIXME
- auto res = new uint8_t[16];
- memcpy(res, responsePayload.data().password_safe_status, 16*sizeof (uint8_t));
- //FIXME return vector<uint8_t> and do copy on C_API side
- return res;
+ vector <uint8_t> NitrokeyManager::get_password_safe_slot_status() {
+ auto responsePayload = GetPasswordSafeSlotStatus::CommandTransaction::run(*device);
+ vector<uint8_t> v = vector<uint8_t>(responsePayload.data().password_safe_status,
+ responsePayload.data().password_safe_status
+ + sizeof(responsePayload.data().password_safe_status));
+ return v;
}
uint8_t NitrokeyManager::get_user_retry_count() {
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index 19b54bd..d2ea991 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -49,7 +49,7 @@ namespace nitrokey {
void enable_password_safe(const char *user_pin);
- uint8_t * get_password_safe_slot_status();
+ vector <uint8_t> get_password_safe_slot_status();
uint8_t get_admin_retry_count();
uint8_t get_user_retry_count();