diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2016-09-09 16:42:31 +0200 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2016-09-10 10:51:53 +0200 |
commit | a46491a97da08e495c92bba8046426678b5564f7 (patch) | |
tree | d332db36123c80ac84474c75b9be4acdff81bf54 /NitrokeyManager.cc | |
parent | 3632e8a32d47950102bc077fd32f9c88316370e9 (diff) | |
download | libnitrokey-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.cc | 10 |
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); } |