mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add SHA1 comparison to text representations from a string
- eases management/control of previously calculated sums - add empty() member function to SHA1Digest - adjust Copyright dates
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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&);
|
||||
|
||||
};
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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&);
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user