aboutsummaryrefslogtreecommitdiff
path: root/include/misc.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 17:18:59 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-03-11 17:18:59 +0100
commit22d05ce647281056d71fbd3c31df3bcd6396188d (patch)
tree90208930f54c47987bfd5ffcf0a0acaaad2510da /include/misc.h
parented5044da43172d86a1aa475473561a4818b7c69c (diff)
parentac6b9c18ef55f4cd36e85069cf0cf82c14e04404 (diff)
downloadlibnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.gz
libnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.bz2
Merge branch 'libnitrokey_3'
Diffstat (limited to 'include/misc.h')
-rw-r--r--include/misc.h18
1 files changed, 15 insertions, 3 deletions
diff --git a/include/misc.h b/include/misc.h
index 5158de0..111d772 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -6,10 +6,21 @@
#include <string.h>
#include "log.h"
#include "LibraryException.h"
+#include <sstream>
+#include <iomanip>
+
namespace nitrokey {
namespace misc {
+ template<typename T>
+ std::string toHex(T value){
+ using namespace std;
+ std::ostringstream oss;
+ oss << std::hex << std::setw(sizeof(value)*2) << std::setfill('0') << value;
+ return oss.str();
+ }
+
template <typename T>
void strcpyT(T& dest, const char* src){
@@ -17,7 +28,7 @@ namespace misc {
// throw EmptySourceStringException(slot_number);
return;
const size_t s_dest = sizeof dest;
- nitrokey::log::Log::instance()(std::string("strcpyT sizes dest src ")
+ LOG(std::string("strcpyT sizes dest src ")
+std::to_string(s_dest)+ " "
+std::to_string(strlen(src))+ " "
,nitrokey::log::Loglevel::DEBUG);
@@ -27,7 +38,7 @@ namespace misc {
strncpy((char*) &dest, src, s_dest);
}
-
+#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
template <typename T>
typename T::CommandPayload get_payload(){
//Create, initialize and return by value command payload
@@ -44,7 +55,8 @@ typename T::CommandPayload get_payload(){
CMDTYPE::CommandTransaction::run(stick, p);
}
- std::string hexdump(const char *p, size_t size, bool print_header=true);
+ std::string hexdump(const char *p, size_t size, bool print_header=true, bool print_ascii=true,
+ bool print_empty=true);
uint32_t stm_crc32(const uint8_t *data, size_t size);
std::vector<uint8_t> hex_string_to_byte(const char* hexString);
}