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
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (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 GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with Classified Ads; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 #ifndef HASH_H
22 #define HASH_H
23 
24 #include <QSslCertificate>
25 
26 
38 class Hash {
39 public:
45  const static int KNumberOfIntsInHash = 5 ;
49  Hash() ;
59  Hash(const quint32 aHash160bits[KNumberOfIntsInHash]) ;
68  Hash(const quint32 aBits1,
69  const quint32 aBits2,
70  const quint32 aBits3,
71  const quint32 aBits4,
72  const quint32 aBits5) ;
79  Hash(const unsigned char aDigest[KNumberOfIntsInHash * 4]) ;
92  Hash(const char* aHexString, int aHexStringLen) ;
98  Hash(const QSslCertificate& aSslCert) ;
99 
104  void fromString(const unsigned char *aBuf) ;
105 
109  QString toString() const ;
110 
115  void fromQVariant(const QVariant& aQVariantHashValue) ;
116 
120  QVariant toQVariant() const ;
121 
126  void calculate(const QByteArray& aBuf) ;
130  bool operator== (const Hash& aHashToCompare) const ;
131  bool operator!= (const Hash& aHashToCompare) const ;
132  bool operator< (const Hash& aHashToCompare) const ;
133  bool operator> (const Hash& aHashToCompare) const ;
134 
138  Hash& operator= (const Hash& aHashToSubstitute) ;
139 
164  Hash distanceFrom (const Hash& aHash) ;
165 
177  Hash operator-(const Hash& aToBeSubstracted) const ;
181  Hash operator+(const Hash& aToBeAdded) const ;
182 
183 private:
184  void setFromCharArray(const unsigned char aDigest[KNumberOfIntsInHash * 4]) ;
185 public:
203 } ;
204 #endif
bool operator==(const Hash &aHashToCompare) const
void fromString(const unsigned char *aBuf)
quint32 iHash160bits[KNumberOfIntsInHash]
Definition: hash.h:202
void calculate(const QByteArray &aBuf)
bool operator<(const Hash &aHashToCompare) const
bool operator>(const Hash &aHashToCompare) const
Hash is class that carries 160-bit digest.
Definition: hash.h:38
Hash operator-(const Hash &aToBeSubstracted) const
void setFromCharArray(const unsigned char aDigest[KNumberOfIntsInHash *4])
static const int KNumberOfIntsInHash
Definition: hash.h:45
Hash operator+(const Hash &aToBeAdded) const
Hash & operator=(const Hash &aHashToSubstitute)
bool operator!=(const Hash &aHashToCompare) const
QVariant toQVariant() const
void fromQVariant(const QVariant &aQVariantHashValue)
QString toString() const
Hash distanceFrom(const Hash &aHash)