From 9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6 Mon Sep 17 00:00:00 2001 From: Linus Jahn Date: Sat, 10 Sep 2022 18:43:57 +0200 Subject: Add multithreaded hashing functions --- src/base/QXmppHashing_p.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/base/QXmppHashing_p.h (limited to 'src/base/QXmppHashing_p.h') 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 +// +// SPDX-License-Identifier: LGPL-2.1-or-later + +#ifndef QXMPPHASHING_H +#define QXMPPHASHING_H + +#include "QXmppError.h" +#include "QXmppGlobal.h" +#include "QXmppHash.h" + +#include +#include +#include + +#include + +template +class QFuture; +class QXmppHash; + +namespace QXmpp::Private { + +struct HashingResult +{ + using Result = std::variant, Cancelled, QXmppError>; + + HashingResult(Result result, std::unique_ptr data) + : result(std::move(result)), data(std::move(data)) + { + } + + Result result; + std::unique_ptr data; +}; + +struct HashVerificationResult +{ + struct NoStrongHashes + { + }; + struct NotMatching + { + }; + struct Verified + { + }; + using Result = std::variant; + + HashVerificationResult(Result result, std::unique_ptr data) + : result(std::move(result)), data(std::move(data)) + { + } + + Result result; + std::unique_ptr data; +}; + +using HashingResultPtr = std::shared_ptr; +using HashVerificationResultPtr = std::shared_ptr; + +bool isHashingAlgorithmSecure(HashAlgorithm algorithm); +uint16_t hashPriority(HashAlgorithm algorithm); + +// QXMPP_EXPORT for unit tests +QXMPP_EXPORT QFuture calculateHashes(std::unique_ptr data, std::vector hashes); +QFuture verifyHashes(std::unique_ptr data, std::vector hashes); + +} // namespace QXmpp::Private + +#endif // QXMPPHASHING_H -- cgit v1.2.3