diff options
| author | Linus Jahn <lnj@kaidan.im> | 2022-09-10 18:43:57 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-09-16 21:26:29 +0200 |
| commit | 9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6 (patch) | |
| tree | 4350efbf7332063f033b265f6d60365e079d0c90 /src/base/QXmppHashing_p.h | |
| parent | 0b6842abd2877886dcb0ca4154e93d9bae1ef80c (diff) | |
| download | qxmpp-9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6.tar.gz | |
Add multithreaded hashing functions
Diffstat (limited to 'src/base/QXmppHashing_p.h')
| -rw-r--r-- | src/base/QXmppHashing_p.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/base/QXmppHashing_p.h b/src/base/QXmppHashing_p.h new file mode 100644 index 00000000..aa8566b2 --- /dev/null +++ b/src/base/QXmppHashing_p.h @@ -0,0 +1,71 @@ +// SPDX-FileCopyrightText: 2022 Linus Jahn <lnj@kaidan.im> +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPHASHING_H +#define QXMPPHASHING_H + +#include "QXmppError.h" +#include "QXmppGlobal.h" +#include "QXmppHash.h" + +#include <memory> +#include <variant> +#include <vector> + +#include <QCryptographicHash> + +template<typename T> +class QFuture; +class QXmppHash; + +namespace QXmpp::Private { + +struct HashingResult +{ + using Result = std::variant<std::vector<QXmppHash>, Cancelled, QXmppError>; + + HashingResult(Result result, std::unique_ptr<QIODevice> data) + : result(std::move(result)), data(std::move(data)) + { + } + + Result result; + std::unique_ptr<QIODevice> data; +}; + +struct HashVerificationResult +{ + struct NoStrongHashes + { + }; + struct NotMatching + { + }; + struct Verified + { + }; + using Result = std::variant<NoStrongHashes, NotMatching, Verified, Cancelled, QXmppError>; + + HashVerificationResult(Result result, std::unique_ptr<QIODevice> data) + : result(std::move(result)), data(std::move(data)) + { + } + + Result result; + std::unique_ptr<QIODevice> data; +}; + +using HashingResultPtr = std::shared_ptr<HashingResult>; +using HashVerificationResultPtr = std::shared_ptr<HashVerificationResult>; + +bool isHashingAlgorithmSecure(HashAlgorithm algorithm); +uint16_t hashPriority(HashAlgorithm algorithm); + +// QXMPP_EXPORT for unit tests +QXMPP_EXPORT QFuture<HashingResultPtr> calculateHashes(std::unique_ptr<QIODevice> data, std::vector<HashAlgorithm> hashes); +QFuture<HashVerificationResultPtr> verifyHashes(std::unique_ptr<QIODevice> data, std::vector<QXmppHash> hashes); + +} // namespace QXmpp::Private + +#endif // QXMPPHASHING_H |
