diff --git a/libretroshare/src/util/rsprint.cc b/libretroshare/src/util/rsprint.cc index 56d372a48..c87fc02f7 100644 --- a/libretroshare/src/util/rsprint.cc +++ b/libretroshare/src/util/rsprint.cc @@ -54,9 +54,12 @@ std::string RsUtil::BinToHex(const std::string &bin) return BinToHex(bin.c_str(), bin.length()); } -std::string RsUtil::BinToHex(const unsigned char *arr, const uint32_t len) +std::string RsUtil::BinToHex(const unsigned char *arr, const uint32_t len,uint32_t max_len) { - return BinToHex((char*)arr,len) ; + if(max_len > 0) + return BinToHex((char*)arr,std::min(max_len,len)) + ((len > max_len)?"...":"") ; + else + return BinToHex((char*)arr,len) ; } std::string RsUtil::BinToHex(const char *arr, const uint32_t len) { diff --git a/libretroshare/src/util/rsprint.h b/libretroshare/src/util/rsprint.h index a2c6405a3..3ab70a411 100644 --- a/libretroshare/src/util/rsprint.h +++ b/libretroshare/src/util/rsprint.h @@ -36,7 +36,10 @@ namespace RsUtil { std::string BinToHex(const std::string &bin); std::string BinToHex(const char *arr, const uint32_t len); -std::string BinToHex(const unsigned char *arr, const uint32_t len); + +// proxy function. When max_len>0 and len>max_len, only the first "max_len" bytes are writen to the string and "..." is happened. + +std::string BinToHex(const unsigned char *arr, const uint32_t len, uint32_t max_len=0); std::string NumberToString(uint64_t n, bool hex=false); std::string HashId(const std::string &id, bool reverse = false); std::vector BinToSha256(const std::vector &in);