From 2bee41e90eb293a30f4896406b9c91cd2e4b7241 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 7 Jul 2021 23:54:21 +0200 Subject: [PATCH] Fix compile of Utilities::Hmac with Qt 6.3 --- src/core/utilities.cpp | 27 ++++++++++++++------------- src/core/utilities.h | 8 ++------ 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index 4c3e49e90..fd554d943 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -469,7 +469,7 @@ void OpenInFileBrowser(const QList &urls) { } -QByteArray Hmac(const QByteArray &key, const QByteArray &data, const HashFunction method) { +QByteArray Hmac(const QByteArray &key, const QByteArray &data, const QCryptographicHash::Algorithm method) { const int kBlockSize = 64; // bytes Q_ASSERT(key.length() <= kBlockSize); @@ -481,28 +481,29 @@ QByteArray Hmac(const QByteArray &key, const QByteArray &data, const HashFunctio inner_padding[i] = inner_padding[i] ^ key[i]; outer_padding[i] = outer_padding[i] ^ key[i]; } - if (Md5_Algo == method) { - return QCryptographicHash::hash(outer_padding + QCryptographicHash::hash(inner_padding + data, QCryptographicHash::Md5), QCryptographicHash::Md5); - } - else if (Sha1_Algo == method) { - return QCryptographicHash::hash(outer_padding + QCryptographicHash::hash(inner_padding + data, QCryptographicHash::Sha1), QCryptographicHash::Sha1); - } - else { // Sha256_Algo, currently default - return QCryptographicHash::hash(outer_padding + QCryptographicHash::hash(inner_padding + data, QCryptographicHash::Sha256), QCryptographicHash::Sha256); - } + + QByteArray part; + part.append(inner_padding); + part.append(data); + + QByteArray total; + total.append(outer_padding); + total.append(QCryptographicHash::hash(part, method)); + + return QCryptographicHash::hash(total, method); } QByteArray HmacSha256(const QByteArray &key, const QByteArray &data) { - return Hmac(key, data, Sha256_Algo); + return Hmac(key, data, QCryptographicHash::Sha256); } QByteArray HmacMd5(const QByteArray &key, const QByteArray &data) { - return Hmac(key, data, Md5_Algo); + return Hmac(key, data, QCryptographicHash::Md5); } QByteArray HmacSha1(const QByteArray &key, const QByteArray &data) { - return Hmac(key, data, Sha1_Algo); + return Hmac(key, data, QCryptographicHash::Sha1); } QByteArray Sha1CoverHash(const QString &artist, const QString &album) { diff --git a/src/core/utilities.h b/src/core/utilities.h index 4c3b57d87..a2b439de4 100644 --- a/src/core/utilities.h +++ b/src/core/utilities.h @@ -41,6 +41,7 @@ #include #include #include +#include #include "core/song.h" @@ -71,12 +72,7 @@ bool Copy(QIODevice *source, QIODevice *destination); void OpenInFileBrowser(const QList &urls); -enum HashFunction { - Md5_Algo, - Sha256_Algo, - Sha1_Algo, -}; -QByteArray Hmac(const QByteArray &key, const QByteArray &data, const HashFunction method); +QByteArray Hmac(const QByteArray &key, const QByteArray &data, const QCryptographicHash::Algorithm method); QByteArray HmacMd5(const QByteArray &key, const QByteArray &data); QByteArray HmacSha256(const QByteArray &key, const QByteArray &data); QByteArray HmacSha1(const QByteArray &key, const QByteArray &data);