1// Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QMESSAGEAUTHENTICATIONCODE_H
5#define QMESSAGEAUTHENTICATIONCODE_H
6
7#include <QtCore/qcryptographichash.h>
8
9QT_BEGIN_NAMESPACE
10
11
12class QMessageAuthenticationCodePrivate;
13class QIODevice;
14
15// implemented in qcryptographichash.cpp
16class Q_CORE_EXPORT QMessageAuthenticationCode
17{
18public:
19#if QT_CORE_REMOVED_SINCE(6, 6)
20 explicit QMessageAuthenticationCode(QCryptographicHash::Algorithm method,
21 const QByteArray &key);
22#endif
23 explicit QMessageAuthenticationCode(QCryptographicHash::Algorithm method,
24 QByteArrayView key = {});
25
26 QMessageAuthenticationCode(QMessageAuthenticationCode &&other) noexcept
27 : d{std::exchange(obj&: other.d, new_val: nullptr)} {}
28 ~QMessageAuthenticationCode();
29
30 QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMessageAuthenticationCode)
31 void swap(QMessageAuthenticationCode &other) noexcept
32 { qt_ptr_swap(lhs&: d, rhs&: other.d); }
33
34 void reset() noexcept;
35
36#if QT_CORE_REMOVED_SINCE(6, 6)
37 void setKey(const QByteArray &key);
38#endif
39 void setKey(QByteArrayView key) noexcept;
40
41 void addData(const char *data, qsizetype length);
42#if QT_CORE_REMOVED_SINCE(6, 6)
43 void addData(const QByteArray &data);
44#endif
45 void addData(QByteArrayView data) noexcept;
46 bool addData(QIODevice *device);
47
48 QByteArrayView resultView() const noexcept;
49 QByteArray result() const;
50
51#if QT_CORE_REMOVED_SINCE(6, 6)
52 static QByteArray hash(const QByteArray &message, const QByteArray &key,
53 QCryptographicHash::Algorithm method);
54#endif
55 static QByteArray hash(QByteArrayView message, QByteArrayView key,
56 QCryptographicHash::Algorithm method);
57
58 static QByteArrayView
59 hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key,
60 QCryptographicHash::Algorithm method) noexcept
61 { return hashInto(buffer: as_writable_bytes(s: buffer), message: {&message, 1}, key, method); }
62 static QByteArrayView
63 hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key,
64 QCryptographicHash::Algorithm method) noexcept
65 { return hashInto(buffer: as_writable_bytes(s: buffer), message: {&message, 1}, key, method); }
66 static QByteArrayView
67 hashInto(QSpan<std::byte> buffer, QByteArrayView message,
68 QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
69 { return hashInto(buffer, message: {&message, 1}, key, method); }
70 static QByteArrayView
71 hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts,
72 QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
73 { return hashInto(buffer: as_writable_bytes(s: buffer), message: messageParts, key, method); }
74 static QByteArrayView
75 hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts,
76 QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
77 { return hashInto(buffer: as_writable_bytes(s: buffer), message: messageParts, key, method); }
78 static QByteArrayView
79 hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> message,
80 QByteArrayView key, QCryptographicHash::Algorithm method) noexcept;
81
82private:
83 Q_DISABLE_COPY(QMessageAuthenticationCode)
84 QMessageAuthenticationCodePrivate *d;
85};
86
87QT_END_NAMESPACE
88
89#endif
90

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtbase/src/corelib/tools/qmessageauthenticationcode.h