Qobuz: Add option for base64 app secret

This commit is contained in:
Jonas Kvinge
2022-10-20 20:47:02 +02:00
parent 5711eef2be
commit f06218f8e3
5 changed files with 51 additions and 28 deletions

View File

@@ -230,6 +230,8 @@ void QobuzService::ReloadSettings() {
app_id_ = s.value("app_id").toString();
app_secret_ = s.value("app_secret").toString();
const bool base64_secret = s.value("base64secret", false).toBool();;
username_ = s.value("username").toString();
QByteArray password = s.value("password").toByteArray();
if (password.isEmpty()) password_.clear();
@@ -248,6 +250,29 @@ void QobuzService::ReloadSettings() {
s.endGroup();
if (base64_secret) {
app_secret_ = DecodeAppSecret(app_secret_);
}
}
QString QobuzService::DecodeAppSecret(const QString &app_secret_base64) {
const QByteArray appid = app_id().toUtf8();
const QByteArray app_secret_binary = QByteArray::fromBase64(app_secret_base64.toUtf8());
QString app_secret_decoded;
for (int x = 0, y = 0; x < app_secret_binary.length(); ++x , ++y) {
if (y == appid.length()) y = 0;
const uint rc = app_secret_binary[x] ^ appid[y];
if (rc > 0xFFFF) {
return app_secret_base64;
}
app_secret_decoded.append(QChar(rc));
}
return app_secret_decoded;
}
void QobuzService::SendLogin() {