Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-14 09:24:17

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