QXmpp Version: 1.10.0
QXmppHashing_p.h
1// SPDX-FileCopyrightText: 2022 Linus Jahn <lnj@kaidan.im>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPHASHING_H
6#define QXMPPHASHING_H
7
8#include "QXmppError.h"
9#include "QXmppGlobal.h"
10#include "QXmppHash.h"
11
12#include <memory>
13#include <variant>
14#include <vector>
15
16#include <QCryptographicHash>
17
18template<typename T>
19class QFuture;
20class QXmppHash;
21
22namespace QXmpp::Private {
23
24struct HashingResult {
25 using Result = std::variant<std::vector<QXmppHash>, Cancelled, QXmppError>;
26
27 HashingResult(Result result, std::unique_ptr<QIODevice> data)
28 : result(std::move(result)), data(std::move(data))
29 {
30 }
31
32 Result result;
33 std::unique_ptr<QIODevice> data;
34};
35
36struct HashVerificationResult {
37 struct NoStrongHashes { };
38 struct NotMatching { };
39 struct Verified { };
40 using Result = std::variant<NoStrongHashes, NotMatching, Verified, Cancelled, QXmppError>;
41
42 HashVerificationResult(Result result, std::unique_ptr<QIODevice> data)
43 : result(std::move(result)), data(std::move(data))
44 {
45 }
46
47 Result result;
48 std::unique_ptr<QIODevice> data;
49};
50
51using HashingResultPtr = std::shared_ptr<HashingResult>;
52using HashVerificationResultPtr = std::shared_ptr<HashVerificationResult>;
53
54bool isHashingAlgorithmSecure(HashAlgorithm algorithm);
55uint16_t hashPriority(HashAlgorithm algorithm);
56
57// QXMPP_EXPORT for unit tests
58QXMPP_EXPORT QFuture<HashingResultPtr> calculateHashes(std::unique_ptr<QIODevice> data, std::vector<HashAlgorithm> hashes);
59QFuture<HashVerificationResultPtr> verifyHashes(std::unique_ptr<QIODevice> data, std::vector<QXmppHash> hashes);
60
61} // namespace QXmpp::Private
62
63#endif // QXMPPHASHING_H
Definition: QXmppHash.h:37
HashAlgorithm
Definition: QXmppHash.h:17
Definition: QXmppError.h:17