rng::getHardRandomHexString is now the same impl as rng::getHexString

so remove one in favor of the other

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I47778f7bce24f0687565aa179b7a3bbea9d95120
pull/8182/head
Caolán McNamara 2024-02-05 11:50:28 +00:00 committed by Michael Meeks
parent 3922137e27
commit f04d3450cd
5 changed files with 6 additions and 24 deletions

View File

@ -148,21 +148,6 @@ namespace Util
return ss.str().substr(0, length);
}
/// Generate a string of harder random characters.
std::string getHardRandomHexString(const std::size_t length)
{
std::stringstream ss;
Poco::HexBinaryEncoder hex(ss);
// a poor fallback but something.
std::vector<char> random = getBytes(length);
hex.rdbuf()->setLineLength(0); // Don't insert line breaks.
hex.write(random.data(), length);
hex.close(); // Flush.
return ss.str().substr(0, length);
}
/// Generates a random string in Base64.
/// Note: May contain '/' characters.
std::string getB64String(const std::size_t length)

View File

@ -95,9 +95,6 @@ namespace Util
/// Generate a string of random characters.
std::string getHexString(const size_t length);
/// Generate a hard random string of characters.
std::string getHardRandomHexString(const size_t length);
/// Generates a random string suitable for
/// file/directory names.
std::string getFilename(const size_t length);

View File

@ -334,7 +334,7 @@ void HttpRequestTests::testSimpleGetSync()
{
constexpr auto testname = "simpleGetSync";
const auto data = Util::rng::getHardRandomHexString(Util::rng::getNext() % 1024);
const auto data = Util::rng::getHexString(Util::rng::getNext() % 1024);
const auto body = std::string(data.data(), data.size());
const std::string URL = "/echo/" + body;
TST_LOG("Requesting URI: [" << URL << ']');
@ -371,7 +371,7 @@ void HttpRequestTests::testChunkedGetSync()
{
constexpr auto testname = "chunkedGetSync";
const auto data = Util::rng::getHardRandomHexString(Util::rng::getNext() % 1024);
const auto data = Util::rng::getHexString(Util::rng::getNext() % 1024);
const auto body = std::string(data.data(), data.size());
const std::string URL = "/echo/chunked/" + body;
TST_LOG("Requesting URI: [" << URL << ']');

View File

@ -2426,7 +2426,7 @@ void COOLWSD::innerInitialize(Application& self)
if (getConfigValue<bool>(conf, "browser_logging", "false"))
{
LogToken = Util::rng::getHardRandomHexString(16);
LogToken = Util::rng::getHexString(16);
}
// First log entry.
@ -2663,7 +2663,7 @@ void COOLWSD::innerInitialize(Application& self)
CleanupChildRoot = ChildRoot;
// Encode the process id into the path for parallel re-use of jails/
ChildRoot += std::to_string(getpid()) + '-' + Util::rng::getHardRandomHexString(8) + '/';
ChildRoot += std::to_string(getpid()) + '-' + Util::rng::getHexString(8) + '/';
LOG_INF("Creating childroot: " + ChildRoot);
}

View File

@ -198,7 +198,7 @@ void ClientSession::rotateClipboardKey(bool notifyClient)
return;
_clipboardKeys[1] = _clipboardKeys[0];
_clipboardKeys[0] = Util::rng::getHardRandomHexString(
_clipboardKeys[0] = Util::rng::getHexString(
ClipboardTokenLengthBytes);
LOG_TRC("Clipboard key on [" << getId() << "] set to " << _clipboardKeys[0] <<
" last was " << _clipboardKeys[1]);
@ -2551,7 +2551,7 @@ void ClientSession::dumpState(std::ostream& os)
const std::string &ClientSession::getOrCreateProxyAccess()
{
if (_proxyAccess.size() <= 0)
_proxyAccess = Util::rng::getHardRandomHexString(
_proxyAccess = Util::rng::getHexString(
ProxyAccessTokenLengthBytes);
return _proxyAccess;
}