Skip to content

Commit

Permalink
UI: Use STL random as fallback
Browse files Browse the repository at this point in the history
For Linux distros still living in the stone ages, use the old
randomization code. Fixes CI not building. We can change it later when
we finalize good random stuff.
  • Loading branch information
jp9000 committed Sep 17, 2021
1 parent 8c9bb3a commit a73586b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions UI/auth-youtube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <QDesktopServices>
#include <QHBoxLayout>
#include <QUrl>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QRandomGenerator>
#endif

#ifdef WIN32
#include <windows.h>
Expand Down Expand Up @@ -193,6 +195,7 @@ void YoutubeAuth::ResetChat()

QString YoutubeAuth::GenerateState()
{
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
char state[YOUTUBE_API_STATE_LENGTH + 1];
QRandomGenerator *rng = QRandomGenerator::system();
int i;
Expand All @@ -202,6 +205,17 @@ QString YoutubeAuth::GenerateState()
state[i] = 0;

return state;
#else
std::uniform_int_distribution<> distr(0, allowedCount);
std::string result;
result.reserve(YOUTUBE_API_STATE_LENGTH);
std::generate_n(std::back_inserter(result), YOUTUBE_API_STATE_LENGTH,
[&] {
return static_cast<char>(
allowedChars[distr(randomSeed)]);
});
return result.c_str();
#endif
}

// Static.
Expand Down
1 change: 1 addition & 0 deletions UI/auth-youtube.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class YoutubeAuth : public OAuthStreamKey {
Q_OBJECT

bool uiLoaded = false;
std::mt19937 randomSeed;
std::string section;

#ifdef BROWSER_AVAILABLE
Expand Down

0 comments on commit a73586b

Please sign in to comment.