diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index 389ca8aa..dcf7318a 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -185,8 +185,7 @@ removeFileExt(std::string filename) return filename.substr(0, dot); } -void -toHex(std::string& subject, int width, const char fill) +std::string to_hex(const std::string& subject, int width, const char fill) { std::stringstream ss; ss << std::hex; @@ -194,7 +193,7 @@ 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 diff --git a/src/lib/base/String.h b/src/lib/base/String.h index 047b6e16..a543cf86 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -75,7 +75,7 @@ std::string removeFileExt(std::string filename); /*! Convert each character in \c subject into hexdecimal form with \c width */ -void toHex(std::string& subject, int width, const char fill = '0'); +std::string to_hex(const std::string& subject, int width, const char fill = '0'); //! Convert to all uppercase /*! diff --git a/src/lib/net/SecureUtils.cpp b/src/lib/net/SecureUtils.cpp index 72d4fbf0..7c4a52da 100644 --- a/src/lib/net/SecureUtils.cpp +++ b/src/lib/net/SecureUtils.cpp @@ -23,7 +23,7 @@ std::string format_ssl_fingerprint(const std::string& fingerprint, bool hex, boo std::string result = fingerprint; if (hex) { // to hexadecimal - barrier::string::toHex(result, 2); + result = barrier::string::to_hex(result, 2); } // all uppercase @@ -36,4 +36,5 @@ std::string format_ssl_fingerprint(const std::string& fingerprint, bool hex, boo result.insert(i * 3 - 1, ":"); } } + return result; } diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 5643aa53..fd771f42 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -59,9 +59,7 @@ TEST(StringTests, toHex_plaintext_hexString) String subject = "foobar"; int width = 2; - string::toHex(subject, width); - - EXPECT_EQ("666f6f626172", subject); + EXPECT_EQ("666f6f626172", string::to_hex(subject, width)); } TEST(StringTests, uppercase_lowercaseInput_uppercaseOutput)