mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 13:18:06 -06:00
committed by
GitHub
parent
a0fa1709d5
commit
06581636a1
@@ -30,14 +30,15 @@
|
||||
#include "bytearray.h"
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVector>
|
||||
#include <QByteArrayView>
|
||||
#include <QList>
|
||||
|
||||
QVector<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const QByteArray &sep, const Qt::SplitBehavior behavior)
|
||||
QList<QByteArrayView> Utils::ByteArray::splitToViews(const QByteArrayView in, const QByteArrayView sep, const Qt::SplitBehavior behavior)
|
||||
{
|
||||
if (sep.isEmpty())
|
||||
return {in};
|
||||
|
||||
QVector<QByteArray> ret;
|
||||
QList<QByteArrayView> ret;
|
||||
ret.reserve((behavior == Qt::KeepEmptyParts)
|
||||
? (1 + (in.size() / sep.size()))
|
||||
: (1 + (in.size() / (sep.size() + 1))));
|
||||
@@ -49,7 +50,7 @@ QVector<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const Q
|
||||
end = in.size();
|
||||
|
||||
// omit empty parts
|
||||
const QByteArray part = QByteArray::fromRawData((in.constData() + head), (end - head));
|
||||
const QByteArrayView part = in.mid(head, (end - head));
|
||||
if (!part.isEmpty() || (behavior == Qt::KeepEmptyParts))
|
||||
ret += part;
|
||||
|
||||
@@ -59,17 +60,6 @@ QVector<QByteArray> Utils::ByteArray::splitToViews(const QByteArray &in, const Q
|
||||
return ret;
|
||||
}
|
||||
|
||||
const QByteArray Utils::ByteArray::midView(const QByteArray &in, const int pos, const int len)
|
||||
{
|
||||
if ((pos < 0) || (pos >= in.size()) || (len == 0))
|
||||
return {};
|
||||
|
||||
const int validLen = ((len < 0) || (pos + len) >= in.size())
|
||||
? in.size() - pos
|
||||
: len;
|
||||
return QByteArray::fromRawData(in.constData() + pos, validLen);
|
||||
}
|
||||
|
||||
QByteArray Utils::ByteArray::toBase32(const QByteArray &in)
|
||||
{
|
||||
const char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
||||
|
||||
@@ -33,15 +33,12 @@
|
||||
#include <QtContainerFwd>
|
||||
|
||||
class QByteArray;
|
||||
class QByteArrayView;
|
||||
|
||||
namespace Utils::ByteArray
|
||||
{
|
||||
// Mimic QStringView(in).split(sep, behavior)
|
||||
QVector<QByteArray> splitToViews(const QByteArray &in, const QByteArray &sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
|
||||
|
||||
// Mimic QByteArray::mid(pos, len) but instead of returning a full-copy,
|
||||
// we only return a partial view
|
||||
const QByteArray midView(const QByteArray &in, int pos, int len = -1);
|
||||
QList<QByteArrayView> splitToViews(QByteArrayView in, QByteArrayView sep, Qt::SplitBehavior behavior = Qt::KeepEmptyParts);
|
||||
|
||||
QByteArray toBase32(const QByteArray &in);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace
|
||||
// Software 'Anaconda' installs its own python interpreter
|
||||
// and `python --version` returns a string like this:
|
||||
// "Python 3.4.3 :: Anaconda 2.3.0 (64-bit)"
|
||||
const QVector<QByteArray> outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", Qt::SkipEmptyParts);
|
||||
const QList<QByteArrayView> outputSplit = Utils::ByteArray::splitToViews(procOutput, " ", Qt::SkipEmptyParts);
|
||||
if (outputSplit.size() <= 1)
|
||||
return false;
|
||||
|
||||
|
||||
@@ -99,12 +99,12 @@ bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QString &pa
|
||||
|
||||
bool Utils::Password::PBKDF2::verify(const QByteArray &secret, const QByteArray &password)
|
||||
{
|
||||
const QVector<QByteArray> list = ByteArray::splitToViews(secret, ":", Qt::SkipEmptyParts);
|
||||
const QList<QByteArrayView> list = ByteArray::splitToViews(secret, ":", Qt::SkipEmptyParts);
|
||||
if (list.size() != 2)
|
||||
return false;
|
||||
|
||||
const QByteArray salt = QByteArray::fromBase64(list[0]);
|
||||
const QByteArray key = QByteArray::fromBase64(list[1]);
|
||||
const QByteArray salt = QByteArray::fromBase64(list[0].toByteArray());
|
||||
const QByteArray key = QByteArray::fromBase64(list[1].toByteArray());
|
||||
|
||||
std::array<unsigned char, 64> outBuf {};
|
||||
const int hmacResult = PKCS5_PBKDF2_HMAC(password.constData(), password.size()
|
||||
|
||||
Reference in New Issue
Block a user