summaryrefslogtreecommitdiff
path: root/include/misc.h
diff options
context:
space:
mode:
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);
}