diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 2dc709e15..dcc37e9a3 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -176,7 +176,7 @@ std::string removeFileExt(std::string filename) return filename.substr(0, dot); } -void toHex(std::string &subject, int width, const char fill) +std::string toHex(const std::string &subject, int width, const char fill) { std::stringstream ss; ss << std::hex; @@ -184,7 +184,7 @@ void toHex(std::string &subject, int width, const char fill) ss << std::setw(width) << std::setfill(fill) << (int)(unsigned char)subject[i]; } - subject = ss.str(); + return ss.str(); } void uppercase(std::string &subject) diff --git a/src/lib/base/String.h b/src/lib/base/String.h index 80fde0405..1af0841e1 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -71,8 +71,9 @@ std::string removeFileExt(std::string filename); //! Convert into hexdecimal /*! Convert each character in \c subject into hexdecimal form with \c width +Return a new hexString */ -void toHex(std::string &subject, int width, const char fill = '0'); +std::string toHex(const std::string &subject, int width, const char fill = '0'); //! Convert to all uppercase /*! diff --git a/src/lib/net/InverseSockets/SslApi.cpp b/src/lib/net/InverseSockets/SslApi.cpp index 2512c924c..7b90c0443 100644 --- a/src/lib/net/InverseSockets/SslApi.cpp +++ b/src/lib/net/InverseSockets/SslApi.cpp @@ -221,7 +221,7 @@ int SslApi::getErrorCode(int status) const void SslApi::formatFingerprint(std::string &fingerprint) const { // to hexidecimal - deskflow::string::toHex(fingerprint, 2); + fingerprint = deskflow::string::toHex(fingerprint, 2); // all uppercase deskflow::string::uppercase(fingerprint); // add colon to separate each 2 charactors diff --git a/src/lib/net/SecureSocket.cpp b/src/lib/net/SecureSocket.cpp index f60aabb58..461df7139 100644 --- a/src/lib/net/SecureSocket.cpp +++ b/src/lib/net/SecureSocket.cpp @@ -625,7 +625,7 @@ void SecureSocket::formatFingerprint(std::string &fingerprint, bool hex, bool se { if (hex) { // to hexidecimal - deskflow::string::toHex(fingerprint, 2); + fingerprint = deskflow::string::toHex(fingerprint, 2); } // all uppercase diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 14947cb8f..d57e93f83 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -56,12 +56,7 @@ TEST(StringTests, sprintf_formatWithArgument_formatedString) TEST(StringTests, toHex_plaintext_hexString) { - std::string subject = "foobar"; - int width = 2; - - string::toHex(subject, width); - - EXPECT_EQ("666f6f626172", subject); + EXPECT_EQ("666f6f626172", string::toHex("foobar", 2)); } TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)