Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 08:30:15

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         Md4,
0025         Md5,
0026         Sha1 = 2,
0027         Sha224,
0028         Sha256,
0029         Sha384,
0030         Sha512,
0031 
0032         Keccak_224 = 7,
0033         Keccak_256,
0034         Keccak_384,
0035         Keccak_512,
0036         RealSha3_224 = 11,
0037         RealSha3_256,
0038         RealSha3_384,
0039         RealSha3_512,
0040 #  ifndef QT_SHA3_KECCAK_COMPAT
0041         Sha3_224 = RealSha3_224,
0042         Sha3_256 = RealSha3_256,
0043         Sha3_384 = RealSha3_384,
0044         Sha3_512 = RealSha3_512,
0045 #  else
0046         Sha3_224 = Keccak_224,
0047         Sha3_256 = Keccak_256,
0048         Sha3_384 = Keccak_384,
0049         Sha3_512 = Keccak_512,
0050 #  endif
0051 
0052         Blake2b_160 = 15,
0053         Blake2b_256,
0054         Blake2b_384,
0055         Blake2b_512,
0056         Blake2s_128,
0057         Blake2s_160,
0058         Blake2s_224,
0059         Blake2s_256,
0060         NumAlgorithms
0061     };
0062     Q_ENUM(Algorithm)
0063 
0064     explicit QCryptographicHash(Algorithm method);
0065     QCryptographicHash(QCryptographicHash &&other) noexcept : d(std::exchange(other.d, nullptr)) {}
0066     ~QCryptographicHash();
0067 
0068     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QCryptographicHash)
0069     void swap(QCryptographicHash &other) noexcept { qt_ptr_swap(d, other.d); }
0070 
0071     void reset() noexcept;
0072     [[nodiscard]] Algorithm algorithm() const noexcept;
0073 
0074 #if QT_DEPRECATED_SINCE(6, 4)
0075     QT_DEPRECATED_VERSION_X_6_4("Use the QByteArrayView overload instead")
0076     void addData(const char *data, qsizetype length);
0077 #endif
0078 #if QT_CORE_REMOVED_SINCE(6, 3)
0079     void addData(const QByteArray &data);
0080 #endif
0081     void addData(QByteArrayView data) noexcept;
0082     bool addData(QIODevice *device);
0083 
0084     QByteArray result() const;
0085     QByteArrayView resultView() const noexcept;
0086 
0087 #if QT_CORE_REMOVED_SINCE(6, 3)
0088     static QByteArray hash(const QByteArray &data, Algorithm method);
0089 #endif
0090     static QByteArray hash(QByteArrayView data, Algorithm method);
0091 
0092     static QByteArrayView hashInto(QSpan<char> buffer, QByteArrayView data, Algorithm method) noexcept
0093     { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); }
0094     static QByteArrayView hashInto(QSpan<uchar> buffer, QByteArrayView data, Algorithm method) noexcept
0095     { return hashInto(as_writable_bytes(buffer), {&data, 1}, method); }
0096     static QByteArrayView hashInto(QSpan<std::byte> buffer, QByteArrayView data, Algorithm method) noexcept
0097     { return hashInto(buffer, {&data, 1}, method); }
0098     static QByteArrayView hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept
0099     { return hashInto(as_writable_bytes(buffer), data, method); }
0100     static QByteArrayView hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept
0101     { return hashInto(as_writable_bytes(buffer), data, method); }
0102     static QByteArrayView hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, Algorithm method) noexcept;
0103 
0104     static int hashLength(Algorithm method);
0105     static bool supportsAlgorithm(Algorithm method);
0106 private:
0107     Q_DISABLE_COPY(QCryptographicHash)
0108     QCryptographicHashPrivate *d;
0109 };
0110 
0111 QT_END_NAMESPACE
0112 
0113 #endif