diff --git a/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C b/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C index dddd523d36..9c6582fa9c 100644 --- a/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C +++ b/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -490,7 +490,7 @@ unsigned Foam::Hasher const short endianTest = 0x0100; // yields 0x01 for big endian - if (*(reinterpret_cast(&endianTest))) + if (*(reinterpret_cast(&endianTest))) { return jenkins_hashbig(key, length, initval); } diff --git a/src/OpenFOAM/primitives/hashes/Hasher/Hasher.H b/src/OpenFOAM/primitives/hashes/Hasher/Hasher.H index 1fa68d4919..85a7ea202c 100644 --- a/src/OpenFOAM/primitives/hashes/Hasher/Hasher.H +++ b/src/OpenFOAM/primitives/hashes/Hasher/Hasher.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/primitives/hashes/Hasher/HasherInt.H b/src/OpenFOAM/primitives/hashes/Hasher/HasherInt.H index 96be6188a9..f5a1e8b3ff 100644 --- a/src/OpenFOAM/primitives/hashes/Hasher/HasherInt.H +++ b/src/OpenFOAM/primitives/hashes/Hasher/HasherInt.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C index d6c9983185..4a9444b6a6 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,7 +74,7 @@ inline uint32_t Foam::SHA1::swapBytes(uint32_t n) const short x = 0x0100; // yields 0x01 for big endian - if (*(reinterpret_cast(&x))) + if (*(reinterpret_cast(&x))) { return n; } @@ -459,10 +459,5 @@ Foam::SHA1Digest Foam::SHA1::digest() const // } // } -// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * // - - -// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * // - // ************************************************************************* // diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H index 4b7080e3df..da19da2d18 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -115,10 +115,10 @@ public: //- Construct null inline SHA1(); - //- Construct and append initial std::string + //- Construct null and append initial std::string explicit inline SHA1(const std::string&); - //- Construct and append initial string + //- Construct null and append initial string explicit inline SHA1(const char*); // Member Functions @@ -145,25 +145,44 @@ public: // Member Operators - //- Equality operator - inline bool operator==(const SHA1Digest&) const; - - //- Inequality operator - inline bool operator!=(const SHA1Digest&) const; - - //- Equality operator + //- Equality operator, compares %digests inline bool operator==(const SHA1&) const; - //- Inequality operator + //- Compare %digest + inline bool operator==(const SHA1Digest&) const; + + //- Compare %digest to (40-byte) text representation (eg, from sha1sum) + // An %empty string is equivalent to + // "0000000000000000000000000000000000000000" + inline bool operator==(const std::string& hexdigits) const; + + //- Compare %digest to (40-byte) text representation (eg, from sha1sum) + // A %null or %empty string is equivalent to + // "0000000000000000000000000000000000000000" + inline bool operator==(const char* hexdigits) const; + + + //- Inequality operator, compares %digests inline bool operator!=(const SHA1&) const; - //- Convert to a digest, calculate current digest from appended data. + //- Inequality operator, compare %digest + inline bool operator!=(const SHA1Digest&) const; + + //- Inequality operator, compares %digests + inline bool operator!=(const std::string& hexdigits) const; + + //- Inequality operator, compare %digest + inline bool operator!=(const char* hexdigits) const; + + + //- Convert to a SHA1Digest, + // calculate current %digest from appended data inline operator SHA1Digest() const; - // Friend Functions // Friend Operators + //- Output the %digest inline friend Ostream& operator<<(Ostream&, const SHA1&); }; diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C index a270dd1d77..7b5d16d722 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -105,7 +105,7 @@ bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const { - return !operator==(rhs); + return !this->operator==(rhs); } diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H index 0402dc9884..19c9698d13 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,6 +38,8 @@ SourceFiles #ifndef SHA1Digest_H #define SHA1Digest_H +#include + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -75,12 +77,33 @@ public: //- Reset the digest to zero void clear(); + //- Return true if the digest is empty (ie, all zero). + bool empty() const; + //- Equality operator bool operator==(const SHA1Digest&) const; + //- Compare to (40-byte) text representation (eg, from sha1sum) + // An %empty string is equivalent to + // "0000000000000000000000000000000000000000" + bool operator==(const std::string& hexdigits) const; + + //- Compare to (40-byte) text representation (eg, from sha1sum) + // A %null or %empty string is equivalent to + // "0000000000000000000000000000000000000000" + bool operator==(const char* hexdigits) const; + + //- Inequality operator bool operator!=(const SHA1Digest&) const; + //- Inequality operator + bool operator!=(const std::string& hexdigits) const; + + //- Inequality operator + bool operator!=(const char* hexdigits) const; + + friend Ostream& operator<<(Ostream&, const SHA1Digest&); friend Istream& operator>>(Istream&, SHA1Digest&); diff --git a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H index e1715bc4c1..aa05de558c 100644 --- a/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H +++ b/src/OpenFOAM/primitives/hashes/SHA1/SHA1I.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -48,9 +48,6 @@ inline Foam::SHA1::SHA1(const char* str) } -// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // inline Foam::SHA1& Foam::SHA1::append(const char* data, size_t len) @@ -79,55 +76,66 @@ inline Foam::SHA1& Foam::SHA1::append(const char* str) // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // +inline bool Foam::SHA1::operator==(const SHA1& rhs) const +{ + return this->digest() == rhs.digest(); +} + + inline bool Foam::SHA1::operator==(const SHA1Digest& rhs) const { return this->digest() == rhs; } -inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const +inline bool Foam::SHA1::operator==(const std::string& hexdigits) const { - return this->digest() != rhs; + return this->digest() == hexdigits; } -inline bool Foam::SHA1::operator==(const SHA1& rhs) const +inline bool Foam::SHA1::operator==(const char* hexdigits) const { - return digest() == rhs.digest(); + return this->digest() == hexdigits; } inline bool Foam::SHA1::operator!=(const SHA1& rhs) const { - return digest() != rhs.digest(); + return !this->operator==(rhs); } -inline Foam::SHA1::operator -Foam::SHA1Digest () const +inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const +{ + return !this->operator==(rhs); +} + + +inline bool Foam::SHA1::operator!=(const std::string& rhs) const +{ + return !this->operator==(rhs); +} + + +inline bool Foam::SHA1::operator!=(const char* rhs) const +{ + return !this->operator==(rhs); +} + + +inline Foam::SHA1::operator Foam::SHA1Digest() const { return digest(); } -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // - - -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // - - -// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * // - - // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha) { - return os << sha.digest(); + return os << sha.digest(); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - - // ************************************************************************* //