|
| 1 | +// Copyright (c) 2020, Mike Gelfand |
| 2 | +// All rights reserved. |
| 3 | +// |
| 4 | +// Redistribution and use in source and binary forms, with or without |
| 5 | +// modification, are permitted provided that the following conditions are met: |
| 6 | +// |
| 7 | +// 1. Redistributions of source code must retain the above copyright notice, this |
| 8 | +// list of conditions and the following disclaimer. |
| 9 | +// |
| 10 | +// 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | +// this list of conditions and the following disclaimer in the documentation |
| 12 | +// and/or other materials provided with the distribution. |
| 13 | +// |
| 14 | +// 3. Neither the name of the copyright holder nor the names of its |
| 15 | +// contributors may be used to endorse or promote products derived from |
| 16 | +// this software without specific prior written permission. |
| 17 | +// |
| 18 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 21 | +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 22 | +// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 23 | +// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 24 | +// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 25 | +// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | +// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 27 | +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | + |
| 29 | +#pragma once |
| 30 | + |
| 31 | +#include "haval.h" |
| 32 | + |
| 33 | +#include <QtGlobal> |
| 34 | + |
| 35 | +QT_BEGIN_NAMESPACE |
| 36 | + |
| 37 | +class QByteArray; |
| 38 | +class QIODevice; |
| 39 | + |
| 40 | +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 41 | +class QByteArrayView; |
| 42 | +#endif |
| 43 | + |
| 44 | +QT_END_NAMESPACE |
| 45 | + |
| 46 | +namespace haval |
| 47 | +{ |
| 48 | + |
| 49 | +template<unsigned int pass_cnt, unsigned int fpt_len> |
| 50 | +class QHaval |
| 51 | +{ |
| 52 | +public: |
| 53 | + using impl_type = haval<pass_cnt, fpt_len>; |
| 54 | + |
| 55 | +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 56 | + using size_type = QT_PREPEND_NAMESPACE(qsizetype); |
| 57 | +#else |
| 58 | + using size_type = int; |
| 59 | +#endif |
| 60 | + |
| 61 | + static constexpr size_type result_size = static_cast<int>(fpt_len) >> 3; |
| 62 | + |
| 63 | +public: |
| 64 | + // initialization |
| 65 | + void start(); |
| 66 | + // updating routine |
| 67 | + void update(const void* data, size_type data_len); |
| 68 | + // finalization |
| 69 | + void endTo(void* data); |
| 70 | + QT_PREPEND_NAMESPACE(QByteArray) end(); |
| 71 | + |
| 72 | + // hash a block |
| 73 | + static QT_PREPEND_NAMESPACE(QByteArray) hash(const void* data, size_type data_len); |
| 74 | + // hash a byte array |
| 75 | + static QT_PREPEND_NAMESPACE(QByteArray) hash(const QT_PREPEND_NAMESPACE(QByteArray)& data); |
| 76 | + // hash a stream |
| 77 | + static QT_PREPEND_NAMESPACE(QByteArray) hash(QT_PREPEND_NAMESPACE(QIODevice)* device); |
| 78 | + |
| 79 | +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) |
| 80 | + // hash a byte array view |
| 81 | + static QT_PREPEND_NAMESPACE(QByteArray) hash(const QT_PREPEND_NAMESPACE(QByteArrayView)& data); |
| 82 | +#endif |
| 83 | + |
| 84 | +private: |
| 85 | + impl_type m_impl; |
| 86 | +}; |
| 87 | + |
| 88 | +} // namespace haval |
0 commit comments