MuldeR's Utilities for Qt
MUtilities
Hash.h
Go to the documentation of this file.
1 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2022 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
21 
29 #pragma once
30 
31 //MUtils
32 #include <MUtils/Global.h>
33 
34 //Qt
35 #include <QByteArray>
36 #include <QFile>
37 
38 namespace MUtils
39 {
40  namespace Hash
41  {
42  static const quint16 HASH_BLAKE2_512 = 0x0000U;
43  static const quint16 HASH_KECCAK_224 = 0x0100U;
44  static const quint16 HASH_KECCAK_256 = 0x0101U;
45  static const quint16 HASH_KECCAK_384 = 0x0102U;
46  static const quint16 HASH_KECCAK_512 = 0x0103U;
47 
57  class MUTILS_API Hash
58  {
59  public:
60  virtual ~Hash(void) {};
61 
73  bool update(const quint8 *const data, const quint32 len) { return process(data, len); }
74 
84  bool update(const QByteArray &data) { return process(((const quint8*)data.constData()), ((quint32)data.length())); }
85 
95  bool update(QFile &file);
96 
106  QByteArray digest(const bool bAsHex = true) { return bAsHex ? finalize().toHex() : finalize(); }
107 
108  protected:
109  Hash(const char* /*key*/ = NULL) {/*nothing to do*/};
110  virtual bool process(const quint8 *const data, const quint32 len) = 0;
111  virtual QByteArray finalize(void) = 0;
112 
113  private:
115  };
116 
128  MUTILS_API Hash *create(const quint16 &hashId, const char *const key = NULL);
129  }
130 }
bool update(const QByteArray &data)
Process the next chunk of input data.
Definition: Hash.h:84
This file contains miscellaneous functions that are generally useful for Qt-based applications...
bool update(const quint8 *const data, const quint32 len)
Process the next chunk of input data.
Definition: Hash.h:73
static const quint16 HASH_BLAKE2_512
Hash algorithm identifier.
Definition: Hash.h:42
static const quint16 HASH_KECCAK_384
Hash algorithm identifier.
Definition: Hash.h:45
Global MUtils namespace.
Definition: CPUFeatures.h:37
#define MUTILS_NO_COPY(CLASS)
Disables copy constructor and assignment operator in the specified class. This macro should be used i...
Definition: Global.h:429
MUTILS_API Hash * create(const quint16 &hashId, const char *const key=NULL)
Create instance of a hash function.
This abstract class specifies the generic interface for all support hash algorithms.
Definition: Hash.h:57
static const quint16 HASH_KECCAK_256
Hash algorithm identifier.
Definition: Hash.h:44
static const quint16 HASH_KECCAK_224
Hash algorithm identifier.
Definition: Hash.h:43
QByteArray digest(const bool bAsHex=true)
Retrieve the hash value.
Definition: Hash.h:106
static const quint16 HASH_KECCAK_512
Hash algorithm identifier.
Definition: Hash.h:46