Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-01 08:50:24

0001 // Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com>
0002 // Copyright (C) 2016 The Qt Company Ltd.
0003 // Copyright (C) 2013 Richard J. Moore <rich@kde.org>.
0004 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0005 
0006 #ifndef QCRYPTOGRAPHICHASH_H
0007 #define QCRYPTOGRAPHICHASH_H
0008 
0009 #include <QtCore/qbytearray.h>
0010 #include <QtCore/qobjectdefs.h>
0011 #include <QtCore/qspan.h>
0012 
0013 QT_BEGIN_NAMESPACE
0014 
0015 
0016 class QCryptographicHashPrivate;
0017 class QIODevice;
0018 
0019 class Q_CORE_EXPORT QCryptographicHash
0020 {
0021     Q_GADGET
0022 public:
0023     enum Algorithm {
0024 #ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
0025         Md4,
0026         Md5,
0027 #endif
0028         Sha1 = 2,
0029 #ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1
0030         Sha224,
0031         Sha256,
0032         Sha384,
0033         Sha512,
0034 
0035         Keccak_224 = 7,
0036         Keccak_256,
0037         Keccak_384,
0038         Keccak_512,
0039         RealSha3_224 = 11,
0040         RealSha3_256,
0041         RealSha3_384,
0042         RealSha3_512,
0043 #  ifndef QT_SHA3_KECCAK_COMPAT
0044         Sha3_224 = RealSha3_224,
0045         Sha3_256 = RealSha3_256,
0046         Sha3_384 = RealSha3_384,
0047         Sha3_512 = RealSha3_512,
0048 #  else
0049         Sha3_224 = Keccak_224,
0050         Sha3_256 = Keccak_256,
0051         Sha3_384 = Keccak_384,
0052         Sha3_512 = Keccak_512,
0053 #  endif
0054 
0055         Blake2b_160 = 15,
0056         Blake2b_256,
0057         Blake2b_384,
0058         Blake2b_512,
0059         Blake2s_128,
0060         Blake2s_160,
0061         Blake2s_224,
0062         Blake2s_256,
0063 #endif
0064         NumAlgorithms
0065     };
0066     Q_ENUM(Algorithm)
0067 
0068     explicit QCryptographicHash(Algorithm method);
0069     QCryptographicHash(QCryptographicHash &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
0070     ~QCryptographicHash();
0071 
0072     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCryptographicHash)
0073     void swap(QCryptographicHash &other) noexcept { qt_ptr_swap(d, other.d); }
0074 
0075     void reset() noexcept;
0076     [[nodiscard]] Algorithm algorithm() const noexcept;
0077 
0078 #if QT_DEPRECATED_SINCE(6, 4)
0079     QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead")
0080     void addData(const char *data, qsizetype length);
0081 #endif
0082 #if QT_CORE_REMOVED_SINCE(6, 3)
0083     void addData(const QByteArray &data);
0084 #endif
0085     void addData(QByteArrayView data) noexcept;
0086     bool addData(QIODevice *device);
0087 
0088     QByteArray result() const;
0089     QByteArrayView resultView() const noexcept;
0090 
0091 #if QT_CORE_REMOVED_SINCE(6, 3)
0092     static QByteArray hash(const QByteArray &data, Algorithm method);
0093 #endif
0094     static QByteArray hash(QByteArrayView data, Algorithm method);
0095 
0096     static QByteArrayView hashInto(QSpan<char> buffer, QByteArrayView data, Algorithm method) noexcept
0097     { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); }
0098     static QByteArrayView hashInto(QSpan<uchar> buffer, QByteArrayView data, Algorithm method) noexcept
0099     { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); }
0100     static QByteArrayView hashInto(QSpan<std::byte> buffer, QByteArrayView data, Algorithm method) noexcept
0101     { return hashInto(buffer, {&data, 1}, method); }
0102     static QByteArrayView hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept
0103     { return hashInto(as_writable_bytes(buffer), data, method); }
0104     static QByteArrayView hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept
0105     { return hashInto(as_writable_bytes(buffer), data, method); }
0106     static QByteArrayView hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept;
0107 
0108     static int hashLength(Algorithm method);
0109     static bool supportsAlgorithm(Algorithm method);
0110 private:
0111     Q_DISABLE_COPY(QCryptographicHash)
0112     QCryptographicHashPrivate *d;
0113 };
0114 
0115 QT_END_NAMESPACE
0116 
0117 #endif