| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2013 Richard J. Moore <[email protected]>. |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #ifndef QCRYPTOGRAPHICHASH_H |
| 42 | #define QCRYPTOGRAPHICHASH_H |
| 43 | |
| 44 | #include <QtCore/qbytearray.h> |
| 45 | #include <QtCore/qobjectdefs.h> |
| 46 | |
| 47 | QT_BEGIN_NAMESPACE |
| 48 | |
| 49 | |
| 50 | class QCryptographicHashPrivate; |
| 51 | class QIODevice; |
| 52 | |
| 53 | class Q_CORE_EXPORT QCryptographicHash |
| 54 | { |
| 55 | Q_GADGET |
| 56 | public: |
| 57 | enum Algorithm { |
| 58 | #ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 |
| 59 | Md4, |
| 60 | Md5, |
| 61 | #endif |
| 62 | Sha1 = 2, |
| 63 | #ifndef QT_CRYPTOGRAPHICHASH_ONLY_SHA1 |
| 64 | Sha224, |
| 65 | Sha256, |
| 66 | Sha384, |
| 67 | Sha512, |
| 68 | |
| 69 | Keccak_224 = 7, |
| 70 | Keccak_256, |
| 71 | Keccak_384, |
| 72 | Keccak_512, |
| 73 | RealSha3_224 = 11, |
| 74 | RealSha3_256, |
| 75 | RealSha3_384, |
| 76 | RealSha3_512, |
| 77 | # ifndef QT_SHA3_KECCAK_COMPAT |
| 78 | Sha3_224 = RealSha3_224, |
| 79 | Sha3_256 = RealSha3_256, |
| 80 | Sha3_384 = RealSha3_384, |
| 81 | Sha3_512 = RealSha3_512 |
| 82 | # else |
| 83 | Sha3_224 = Keccak_224, |
| 84 | Sha3_256 = Keccak_256, |
| 85 | Sha3_384 = Keccak_384, |
| 86 | Sha3_512 = Keccak_512 |
| 87 | # endif |
| 88 | #endif |
| 89 | }; |
| 90 | Q_ENUM(Algorithm) |
| 91 | |
| 92 | explicit QCryptographicHash(Algorithm method); |
| 93 | ~QCryptographicHash(); |
| 94 | |
| 95 | void reset(); |
| 96 | |
| 97 | void addData(const char *data, int length); |
| 98 | void addData(const QByteArray &data); |
| 99 | bool addData(QIODevice* device); |
| 100 | |
| 101 | QByteArray result() const; |
| 102 | |
| 103 | static QByteArray hash(const QByteArray &data, Algorithm method); |
| 104 | static int hashLength(Algorithm method); |
| 105 | private: |
| 106 | Q_DISABLE_COPY(QCryptographicHash) |
| 107 | QCryptographicHashPrivate *d; |
| 108 | }; |
| 109 | |
| 110 | QT_END_NAMESPACE |
| 111 | |
| 112 | #endif |
| 113 | |