diff --git a/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C b/src/OpenFOAM/primitives/hashes/Hasher/Hasher.C index dddd523d36ce631d2ac2c5995a144e9a93b0734f..9c6582fa9c323f7c54b6e98c1cd41967fd45b10f 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<const char *>(&endianTest))) + if (*(reinterpret_cast<const char*>(&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 1fa68d4919330ed1540bd7f7e686818c99ff73d1..85a7ea202c03754cd158fca66c27aa11e6bd3c02 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 96be6188a9878e2620d8dc3a181fb4b9f8e2d2a5..f5a1e8b3ff132b1e1b60048e978460ca7c4cd1a8 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 d6c99831854489b107f1f425d3c591e01823c5ee..4a9444b6a6bf0cb2c6ca65de5ede8df23b695c25 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<const char *>(&x))) + if (*(reinterpret_cast<const char*>(&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 4b7080e3df0fe8e362a7206d16773003e16d0544..da19da2d182c0d35189d7bbddcd32b67b05e95f0 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 + //- Equality operator, compares %digests + inline bool operator==(const SHA1&) const; + + //- Compare %digest inline bool operator==(const SHA1Digest&) const; - //- Inequality operator - 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; - //- Equality operator - inline bool operator==(const SHA1&) const; - //- Inequality operator + //- 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 a270dd1d774960297818a47da54bf1b92a433785..7b5d16d722a18a9791eb453f82de1db5408eac54 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 0402dc9884c7ab37450341e28ec2e076b0c88cb2..19c9698d13d860d63082a4f60c14d34bc589774a 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 <string> + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 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 e1715bc4c139c7b3303fffc58c7e809188f4e78c..aa05de558c11fc2cb6e1105861e1760948624948 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 digest(); + return !this->operator==(rhs); } -// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * // +inline bool Foam::SHA1::operator!=(const std::string& rhs) const +{ + return !this->operator==(rhs); +} -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // +inline bool Foam::SHA1::operator!=(const char* rhs) const +{ + return !this->operator==(rhs); +} -// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * // +inline Foam::SHA1::operator Foam::SHA1Digest() const +{ + return digest(); +} // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha) { - return os << sha.digest(); + return os << sha.digest(); } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - - // ************************************************************************* //