Classified ads
hash.h
Go to the documentation of this file.
1 /* -*-C++-*-
2  Classified Ads is Copyright (c) Antti Jarvinen 2013.
3 
4  This file is part of Classified Ads.
5 
6  Classified Ads is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Classified Ads is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with Classified Ads. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #ifndef HASH_H
21 #define HASH_H
22 
23 #include <QSslCertificate>
24 
25 
37 class Hash {
38 public:
44  const static int KNumberOfIntsInHash = 5 ;
48  Hash() ;
58  Hash(const quint32 aHash160bits[KNumberOfIntsInHash]) ;
67  Hash(const quint32 aBits1,
68  const quint32 aBits2,
69  const quint32 aBits3,
70  const quint32 aBits4,
71  const quint32 aBits5) ;
78  Hash(const unsigned char aDigest[KNumberOfIntsInHash * 4]) ;
91  Hash(const char* aHexString, int aHexStringLen) ;
97  Hash(const QSslCertificate& aSslCert) ;
98 
103  void fromString(const unsigned char *aBuf) ;
104 
108  QString toString() const ;
109 
114  void fromQVariant(const QVariant& aQVariantHashValue) ;
115 
119  QVariant toQVariant() const ;
120 
125  void calculate(const QByteArray& aBuf) ;
129  bool operator== (const Hash& aHashToCompare) const ;
130  bool operator!= (const Hash& aHashToCompare) const ;
131  bool operator< (const Hash& aHashToCompare) const ;
132  bool operator> (const Hash& aHashToCompare) const ;
133 
137  Hash& operator= (const Hash& aHashToSubstitute) ;
138 
163  Hash distanceFrom (const Hash& aHash) ;
164 
176  Hash operator-(const Hash& aToBeSubstracted) const ;
180  Hash operator+(const Hash& aToBeAdded) const ;
181 
182 private:
183  void setFromCharArray(const unsigned char aDigest[KNumberOfIntsInHash * 4]) ;
184 public:
202 } ;
203 #endif
QString toString() const
void fromString(const unsigned char *aBuf)
quint32 iHash160bits[KNumberOfIntsInHash]
Definition: hash.h:201
void calculate(const QByteArray &aBuf)
bool operator<(const Hash &aHashToCompare) const
Hash is class that carries 160-bit digest.
Definition: hash.h:37
bool operator!=(const Hash &aHashToCompare) const
Hash operator+(const Hash &aToBeAdded) const
void setFromCharArray(const unsigned char aDigest[KNumberOfIntsInHash *4])
bool operator==(const Hash &aHashToCompare) const
static const int KNumberOfIntsInHash
Definition: hash.h:44
Hash & operator=(const Hash &aHashToSubstitute)
void fromQVariant(const QVariant &aQVariantHashValue)
QVariant toQVariant() const
Hash operator-(const Hash &aToBeSubstracted) const
Hash distanceFrom(const Hash &aHash)
bool operator>(const Hash &aHashToCompare) const