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
58private:
59 Q_DISABLE_COPY(QMessageAuthenticationCode)
60 QMessageAuthenticationCodePrivate *d;
61};
62
63QT_END_NAMESPACE
64
65#endif
66

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