diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 17:18:59 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 17:18:59 +0100 |
commit | 22d05ce647281056d71fbd3c31df3bcd6396188d (patch) | |
tree | 90208930f54c47987bfd5ffcf0a0acaaad2510da /misc.cc | |
parent | ed5044da43172d86a1aa475473561a4818b7c69c (diff) | |
parent | ac6b9c18ef55f4cd36e85069cf0cf82c14e04404 (diff) | |
download | libnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.gz libnitrokey-22d05ce647281056d71fbd3c31df3bcd6396188d.tar.bz2 |
Merge branch 'libnitrokey_3'
Diffstat (limited to 'misc.cc')
-rw-r--r-- | misc.cc | 34 |
1 files changed, 20 insertions, 14 deletions
@@ -5,18 +5,21 @@ #include <cstdlib> #include <cstring> #include "LibraryException.h" +#include <vector> namespace nitrokey { namespace misc { -std::vector<uint8_t> hex_string_to_byte(const char* hexString){ + + +::std::vector<uint8_t> hex_string_to_byte(const char* hexString){ const size_t big_string_size = 256; //arbitrary 'big' number const size_t s_size = strlen(hexString); const size_t d_size = s_size/2; if (s_size%2!=0 || s_size>big_string_size){ throw InvalidHexString(0); } - auto data = std::vector<uint8_t>(); + auto data = ::std::vector<uint8_t>(); data.reserve(d_size); char buf[2]; @@ -36,8 +39,9 @@ std::vector<uint8_t> hex_string_to_byte(const char* hexString){ }; #include <cctype> -std::string hexdump(const char *p, size_t size, bool print_header) { - std::stringstream out; +::std::string hexdump(const char *p, size_t size, bool print_header, + bool print_ascii, bool print_empty) { + ::std::stringstream out; char formatbuf[128]; const char *pstart = p; @@ -53,19 +57,21 @@ std::string hexdump(const char *p, size_t size, bool print_header) { snprintf(formatbuf, 128, "%02x ", uint8_t(*p)); out << formatbuf; } else { - out << "-- "; + if(print_empty) + out << "-- "; } } - out << "\t"; - - for (const char *le = pp + 16; pp < le && pp < pend; pp++) { - if (std::isgraph(*pp)) - out << uint8_t(*pp); - else - out << '.'; - } - out << std::endl; + if(print_ascii){ + out << "\t"; + for (const char *le = pp + 16; pp < le && pp < pend; pp++) { + if (std::isgraph(*pp)) + out << uint8_t(*pp); + else + out << '.'; + } + } + out << ::std::endl; } return out.str(); } |