diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-01-18 00:11:25 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 15:41:39 +0100 |
commit | 3d54b4ea0c96a2420973dc840c1b32545bf2b05d (patch) | |
tree | 3741caeaf40c6b98374bc01c4e34ed94decd6bd5 /misc.cc | |
parent | 56bd3e2c4353cfc1b902c6dfb55df0ef563c5372 (diff) | |
download | libnitrokey-3d54b4ea0c96a2420973dc840c1b32545bf2b05d.tar.gz libnitrokey-3d54b4ea0c96a2420973dc840c1b32545bf2b05d.tar.bz2 |
Fix getting card serial
todo: remove whitespace at the string end
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'misc.cc')
-rw-r--r-- | misc.cc | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -36,7 +36,8 @@ 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::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,18 +54,20 @@ 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 << '.'; - } + 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(); |