1
0
mirror of https://github.com/strawberrymusicplayer/strawberry synced 2024-12-14 01:26:00 +01:00

Fix compile of Utilities::Hmac with Qt 6.3

This commit is contained in:
Jonas Kvinge 2021-07-07 23:54:21 +02:00
parent 2a7312f2b4
commit 2bee41e90e
2 changed files with 16 additions and 19 deletions

View File

@ -469,7 +469,7 @@ void OpenInFileBrowser(const QList<QUrl> &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) {

View File

@ -41,6 +41,7 @@
#include <QColor>
#include <QRegion>
#include <QtEvents>
#include <QCryptographicHash>
#include "core/song.h"
@ -71,12 +72,7 @@ bool Copy(QIODevice *source, QIODevice *destination);
void OpenInFileBrowser(const QList<QUrl> &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);