Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-17 09:09:23

0001 // Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru>
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QMESSAGEAUTHENTICATIONCODE_H
0005 #define QMESSAGEAUTHENTICATIONCODE_H
0006 
0007 #include <QtCore/qcryptographichash.h>
0008 
0009 QT_BEGIN_NAMESPACE
0010 
0011 
0012 class QMessageAuthenticationCodePrivate;
0013 class QIODevice;
0014 
0015 // implemented in qcryptographichash.cpp
0016 class Q_CORE_EXPORT QMessageAuthenticationCode
0017 {
0018 public:
0019 #if QT_CORE_REMOVED_SINCE(6, 6)
0020     explicit QMessageAuthenticationCode(QCryptographicHash::Algorithm method,
0021                                         const QByteArray &key);
0022 #endif
0023     explicit QMessageAuthenticationCode(QCryptographicHash::Algorithm method,
0024                                         QByteArrayView key = {});
0025 
0026     QMessageAuthenticationCode(QMessageAuthenticationCode &&other) noexcept
0027         : d{std::exchange(other.d, nullptr)} {}
0028     ~QMessageAuthenticationCode();
0029 
0030     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QMessageAuthenticationCode)
0031     void swap(QMessageAuthenticationCode &other) noexcept
0032     { qt_ptr_swap(d, other.d); }
0033 
0034     void reset() noexcept;
0035 
0036 #if QT_CORE_REMOVED_SINCE(6, 6)
0037     void setKey(const QByteArray &key);
0038 #endif
0039     void setKey(QByteArrayView key) noexcept;
0040 
0041     void addData(const char *data, qsizetype length);
0042 #if QT_CORE_REMOVED_SINCE(6, 6)
0043     void addData(const QByteArray &data);
0044 #endif
0045     void addData(QByteArrayView data) noexcept;
0046     bool addData(QIODevice *device);
0047 
0048     QByteArrayView resultView() const noexcept;
0049     QByteArray result() const;
0050 
0051 #if QT_CORE_REMOVED_SINCE(6, 6)
0052     static QByteArray hash(const QByteArray &message, const QByteArray &key,
0053                            QCryptographicHash::Algorithm method);
0054 #endif
0055     static QByteArray hash(QByteArrayView message, QByteArrayView key,
0056                            QCryptographicHash::Algorithm method);
0057 
0058     static QByteArrayView
0059     hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key,
0060              QCryptographicHash::Algorithm method) noexcept
0061     { return hashInto(as_writable_bytes(buffer), {&message, 1}, key, method); }
0062     static QByteArrayView
0063     hashInto(QSpan<uchar> buffer, QByteArrayView message, QByteArrayView key,
0064              QCryptographicHash::Algorithm method) noexcept
0065     { return hashInto(as_writable_bytes(buffer), {&message, 1}, key, method); }
0066     static QByteArrayView
0067     hashInto(QSpan<std::byte> buffer, QByteArrayView message,
0068              QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
0069     { return hashInto(buffer, {&message, 1}, key, method); }
0070     static QByteArrayView
0071     hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> messageParts,
0072              QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
0073     { return hashInto(as_writable_bytes(buffer), messageParts, key, method); }
0074     static QByteArrayView
0075     hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> messageParts,
0076              QByteArrayView key, QCryptographicHash::Algorithm method) noexcept
0077     { return hashInto(as_writable_bytes(buffer), messageParts, key, method); }
0078     static QByteArrayView
0079     hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> message,
0080              QByteArrayView key, QCryptographicHash::Algorithm method) noexcept;
0081 
0082 private:
0083     Q_DISABLE_COPY(QMessageAuthenticationCode)
0084     QMessageAuthenticationCodePrivate *d;
0085 };
0086 
0087 QT_END_NAMESPACE
0088 
0089 #endif