diff options
author | flow <thiagodonato300@gmail.com> | 2022-04-27 18:36:11 -0300 |
---|---|---|
committer | flow <thiagodonato300@gmail.com> | 2022-05-12 18:11:55 -0300 |
commit | 040ee919e5ea71364daa08c30e09c843976f5734 (patch) | |
tree | c65db37c7aa199592135020d3114aa808415764c /launcher/net/ChecksumValidator.h | |
parent | efa3fbff39bf0dabebdf1c6330090ee320895a4d (diff) | |
download | PrismLauncher-040ee919e5ea71364daa08c30e09c843976f5734.tar.gz PrismLauncher-040ee919e5ea71364daa08c30e09c843976f5734.tar.bz2 PrismLauncher-040ee919e5ea71364daa08c30e09c843976f5734.zip |
refactor: more net cleanup
This runs clang-tidy on some other files in launcher/net/.
This also makes use of some JSON wrappers in HttpMetaCache, instead of
using the Qt stuff directly.
Lastly, this removes useless null checks (crashes don't occur because of
this, but because of concurrent usage / free of the QByteArray pointer),
and fix a fixme in Download.h
Diffstat (limited to 'launcher/net/ChecksumValidator.h')
-rw-r--r-- | launcher/net/ChecksumValidator.h | 48 |
1 files changed, 20 insertions, 28 deletions
diff --git a/launcher/net/ChecksumValidator.h b/launcher/net/ChecksumValidator.h index 0d6b19c2..8a8b10d5 100644 --- a/launcher/net/ChecksumValidator.h +++ b/launcher/net/ChecksumValidator.h @@ -1,55 +1,47 @@ #pragma once #include "Validator.h" + #include <QCryptographicHash> -#include <memory> #include <QFile> namespace Net { -class ChecksumValidator: public Validator -{ -public: /* con/des */ +class ChecksumValidator : public Validator { + public: ChecksumValidator(QCryptographicHash::Algorithm algorithm, QByteArray expected = QByteArray()) - :m_checksum(algorithm), m_expected(expected) - { - }; - virtual ~ChecksumValidator() {}; + : m_checksum(algorithm), m_expected(expected){}; + virtual ~ChecksumValidator() = default; -public: /* methods */ - bool init(QNetworkRequest &) override + public: + auto init(QNetworkRequest&) -> bool override { m_checksum.reset(); return true; } - bool write(QByteArray & data) override + + auto write(QByteArray& data) -> bool override { m_checksum.addData(data); return true; } - bool abort() override - { - return true; - } - bool validate(QNetworkReply &) override + + auto abort() -> bool override { return true; } + + auto validate(QNetworkReply&) -> bool override { - if(m_expected.size() && m_expected != hash()) - { + if (m_expected.size() && m_expected != hash()) { qWarning() << "Checksum mismatch, download is bad."; return false; } return true; } - QByteArray hash() - { - return m_checksum.result(); - } - void setExpected(QByteArray expected) - { - m_expected = expected; - } -private: /* data */ + auto hash() -> QByteArray { return m_checksum.result(); } + + void setExpected(QByteArray expected) { m_expected = expected; } + + private: QCryptographicHash m_checksum; QByteArray m_expected; }; -}
\ No newline at end of file +} // namespace Net |