summaryrefslogtreecommitdiff
path: root/NitrokeyManager.cc
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-09-09 16:42:31 +0200
committerSzczepan Zalega <szczepan@nitrokey.com>2016-09-10 10:51:53 +0200
commita46491a97da08e495c92bba8046426678b5564f7 (patch)
treed332db36123c80ac84474c75b9be4acdff81bf54 /NitrokeyManager.cc
parent3632e8a32d47950102bc077fd32f9c88316370e9 (diff)
downloadlibnitrokey-a46491a97da08e495c92bba8046426678b5564f7.tar.gz
libnitrokey-a46491a97da08e495c92bba8046426678b5564f7.tar.bz2
Remove asserts in favor of exceptions or warnings. Test changes in Python.
On possible data truncation return LibraryError(exception) instead of silently truncating and logging warning Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'NitrokeyManager.cc')
-rw-r--r--NitrokeyManager.cc10
1 files changed, 7 insertions, 3 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index c88f717..d827292 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -2,6 +2,7 @@
#include <iostream>
#include "include/NitrokeyManager.h"
#include "include/LibraryException.h"
+#include <algorithm>
namespace nitrokey{
@@ -157,10 +158,13 @@ namespace nitrokey{
return erase_slot(slot_number, temporary_password);
}
- #include <cassert>
template <typename T, typename U>
- void vector_copy(T& dest, std::vector<U> vec){
- assert(sizeof(dest)>=vec.size());
+ void vector_copy(T& dest, std::vector<U> &vec){
+ const size_t d_size = sizeof(dest);
+ if(d_size < vec.size()){
+ throw TargetBufferSmallerThanSource(vec.size(), d_size);
+ }
+ std::fill(dest, dest+d_size, 0);
std::copy(vec.begin(), vec.end(), dest);
}