aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/misc.h3
-rw-r--r--include/stick10_commands.h2
-rw-r--r--misc.cc23
3 files changed, 16 insertions, 12 deletions
diff --git a/include/misc.h b/include/misc.h
index 5158de0..9e4659d 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -44,7 +44,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);
}
diff --git a/include/stick10_commands.h b/include/stick10_commands.h
index 9b72e92..fb362fb 100644
--- a/include/stick10_commands.h
+++ b/include/stick10_commands.h
@@ -332,7 +332,7 @@ class GetStatus : Command<CommandID::GET_STATUS> {
std::string get_card_serial_hex() const {
return ::nitrokey::misc::hexdump((const char *)(card_serial),
- sizeof card_serial, false);
+ sizeof card_serial, false, false, false);
}
std::string dissect() const {
diff --git a/misc.cc b/misc.cc
index 3f15520..a76bfb6 100644
--- a/misc.cc
+++ b/misc.cc
@@ -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();