From a73586b8b1b51f590f353d4befbc7f888ecfd06c Mon Sep 17 00:00:00 2001 From: jp9000 Date: Fri, 17 Sep 2021 02:57:31 -0700 Subject: [PATCH] UI: Use STL random as fallback 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. --- UI/auth-youtube.cpp | 14 ++++++++++++++ UI/auth-youtube.hpp | 1 + 2 files changed, 15 insertions(+) diff --git a/UI/auth-youtube.cpp b/UI/auth-youtube.cpp index 65aec617c..ea1a34344 100644 --- a/UI/auth-youtube.cpp +++ b/UI/auth-youtube.cpp @@ -7,7 +7,9 @@ #include #include #include +#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)) #include +#endif #ifdef WIN32 #include @@ -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; @@ -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( + allowedChars[distr(randomSeed)]); + }); + return result.c_str(); +#endif } // Static. diff --git a/UI/auth-youtube.hpp b/UI/auth-youtube.hpp index 21da2e481..31b2ca583 100644 --- a/UI/auth-youtube.hpp +++ b/UI/auth-youtube.hpp @@ -20,6 +20,7 @@ class YoutubeAuth : public OAuthStreamKey { Q_OBJECT bool uiLoaded = false; + std::mt19937 randomSeed; std::string section; #ifdef BROWSER_AVAILABLE