mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
moved SHA1::Digest class to SHA1Digest to allow forward declarations
This commit is contained in:
@ -41,7 +41,7 @@ using namespace Foam;
|
|||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
SHA1 sha;
|
SHA1 sha;
|
||||||
SHA1::Digest shaDig;
|
SHA1Digest shaDig;
|
||||||
|
|
||||||
std::string str("The quick brown fox jumps over the lazy dog");
|
std::string str("The quick brown fox jumps over the lazy dog");
|
||||||
Info<< shaDig << nl;
|
Info<< shaDig << nl;
|
||||||
@ -72,7 +72,7 @@ int main(int argc, char * argv[])
|
|||||||
sha.clear();
|
sha.clear();
|
||||||
sha.append(str);
|
sha.append(str);
|
||||||
|
|
||||||
SHA1::Digest shaDig_A = sha;
|
SHA1Digest shaDig_A = sha;
|
||||||
|
|
||||||
SHA1 sha_A = sha;
|
SHA1 sha_A = sha;
|
||||||
|
|
||||||
|
|||||||
@ -158,7 +158,7 @@ public:
|
|||||||
:
|
:
|
||||||
OSstream
|
OSstream
|
||||||
(
|
(
|
||||||
*(new osha1stream()),
|
*(new osha1stream),
|
||||||
"OSHA1stream.sinkFile_",
|
"OSHA1stream.sinkFile_",
|
||||||
format,
|
format,
|
||||||
version
|
version
|
||||||
@ -185,7 +185,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
//- Return SHA1::Digest for the data processed until now
|
//- Return SHA1::Digest for the data processed until now
|
||||||
Foam::SHA1::Digest digest()
|
Foam::SHA1Digest digest()
|
||||||
{
|
{
|
||||||
return sha1().digest();
|
return sha1().digest();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -233,7 +233,7 @@ Foam::label Foam::dictionary::endLineNumber() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::SHA1::Digest Foam::dictionary::digest() const
|
Foam::SHA1Digest Foam::dictionary::digest() const
|
||||||
{
|
{
|
||||||
OSHA1stream os;
|
OSHA1stream os;
|
||||||
|
|
||||||
|
|||||||
@ -60,7 +60,6 @@ SourceFiles
|
|||||||
#include "HashTable.H"
|
#include "HashTable.H"
|
||||||
#include "wordList.H"
|
#include "wordList.H"
|
||||||
#include "className.H"
|
#include "className.H"
|
||||||
#include "SHA1.H"
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -70,6 +69,8 @@ namespace Foam
|
|||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
class regExp;
|
class regExp;
|
||||||
class dictionary;
|
class dictionary;
|
||||||
|
class SHA1Digest;
|
||||||
|
|
||||||
Istream& operator>>(Istream&, dictionary&);
|
Istream& operator>>(Istream&, dictionary&);
|
||||||
Ostream& operator<<(Ostream&, const dictionary&);
|
Ostream& operator<<(Ostream&, const dictionary&);
|
||||||
|
|
||||||
@ -212,7 +213,7 @@ public:
|
|||||||
label endLineNumber() const;
|
label endLineNumber() const;
|
||||||
|
|
||||||
//- Return the SHA1 digest of the dictionary contents
|
//- Return the SHA1 digest of the dictionary contents
|
||||||
SHA1::Digest digest() const;
|
SHA1Digest digest() const;
|
||||||
|
|
||||||
|
|
||||||
// Search and lookup
|
// Search and lookup
|
||||||
|
|||||||
@ -324,7 +324,7 @@ Foam::SHA1::processBlock(const void *data, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Foam::SHA1::calcDigest(SHA1::Digest& dig) const
|
void Foam::SHA1::calcDigest(SHA1Digest& dig) const
|
||||||
{
|
{
|
||||||
if (bufTotal_[0] || bufTotal_[1])
|
if (bufTotal_[0] || bufTotal_[1])
|
||||||
{
|
{
|
||||||
@ -411,9 +411,9 @@ bool Foam::SHA1::finalize()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Foam::SHA1::Digest Foam::SHA1::digest() const
|
Foam::SHA1Digest Foam::SHA1::digest() const
|
||||||
{
|
{
|
||||||
SHA1::Digest dig;
|
SHA1Digest dig;
|
||||||
|
|
||||||
if (finalized_)
|
if (finalized_)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -31,10 +31,12 @@ Description
|
|||||||
|
|
||||||
Adapted from the gnulib implementation.
|
Adapted from the gnulib implementation.
|
||||||
|
|
||||||
|
SeeAlso
|
||||||
|
Foam::SHA1Digest
|
||||||
|
|
||||||
SourceFiles
|
SourceFiles
|
||||||
SHA1I.H
|
SHA1I.H
|
||||||
SHA1.C
|
SHA1.C
|
||||||
SHA1Digest.C
|
|
||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ SourceFiles
|
|||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <stdint.h> // C++0x uses <cstdint>
|
#include <stdint.h> // C++0x uses <cstdint>
|
||||||
|
|
||||||
|
#include "SHA1Digest.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
namespace Foam
|
namespace Foam
|
||||||
@ -55,6 +59,7 @@ class Ostream;
|
|||||||
|
|
||||||
// Forward declaration of friend functions and operators
|
// Forward declaration of friend functions and operators
|
||||||
class SHA1;
|
class SHA1;
|
||||||
|
class SHA1Digest;
|
||||||
Ostream& operator<<(Ostream&, const SHA1&);
|
Ostream& operator<<(Ostream&, const SHA1&);
|
||||||
|
|
||||||
|
|
||||||
@ -64,42 +69,6 @@ Ostream& operator<<(Ostream&, const SHA1&);
|
|||||||
|
|
||||||
class SHA1
|
class SHA1
|
||||||
{
|
{
|
||||||
public:
|
|
||||||
|
|
||||||
// Public classes
|
|
||||||
|
|
||||||
//- The SHA1 digest itself
|
|
||||||
class Digest
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
friend class SHA1;
|
|
||||||
|
|
||||||
//- The length of the digest contents
|
|
||||||
static const unsigned length = 20;
|
|
||||||
|
|
||||||
//- Construct null
|
|
||||||
Digest();
|
|
||||||
|
|
||||||
//- Reset the digest to zero
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
//- Equality operator
|
|
||||||
bool operator==(const Digest&) const;
|
|
||||||
|
|
||||||
//- Inequality operator
|
|
||||||
bool operator!=(const Digest&) const;
|
|
||||||
|
|
||||||
friend Ostream& operator<<(Ostream&, const SHA1::Digest&);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
//- The digest contents
|
|
||||||
unsigned char v_[length];
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
// Private data
|
// Private data
|
||||||
|
|
||||||
//- Track if the hashsum has been finalized (added count, etc)
|
//- Track if the hashsum has been finalized (added count, etc)
|
||||||
@ -138,7 +107,7 @@ private:
|
|||||||
void processBytes(const void *data, size_t len);
|
void processBytes(const void *data, size_t len);
|
||||||
|
|
||||||
//- Calculate current digest from appended data.
|
//- Calculate current digest from appended data.
|
||||||
void calcDigest(SHA1::Digest&) const;
|
void calcDigest(SHA1Digest&) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -172,16 +141,16 @@ public:
|
|||||||
bool finalize();
|
bool finalize();
|
||||||
|
|
||||||
//- Calculate current digest from appended data.
|
//- Calculate current digest from appended data.
|
||||||
Digest digest() const;
|
SHA1Digest digest() const;
|
||||||
|
|
||||||
|
|
||||||
// Member Operators
|
// Member Operators
|
||||||
|
|
||||||
//- Equality operator
|
//- Equality operator
|
||||||
inline bool operator==(const SHA1::Digest&) const;
|
inline bool operator==(const SHA1Digest&) const;
|
||||||
|
|
||||||
//- Inequality operator
|
//- Inequality operator
|
||||||
inline bool operator!=(const SHA1::Digest&) const;
|
inline bool operator!=(const SHA1Digest&) const;
|
||||||
|
|
||||||
//- Equality operator
|
//- Equality operator
|
||||||
inline bool operator==(const SHA1&) const;
|
inline bool operator==(const SHA1&) const;
|
||||||
@ -190,8 +159,7 @@ public:
|
|||||||
inline bool operator!=(const SHA1&) const;
|
inline bool operator!=(const SHA1&) const;
|
||||||
|
|
||||||
//- Convert to a digest, calculate current digest from appended data.
|
//- Convert to a digest, calculate current digest from appended data.
|
||||||
inline operator SHA1::Digest() const;
|
inline operator SHA1Digest() const;
|
||||||
|
|
||||||
|
|
||||||
// Friend Functions
|
// Friend Functions
|
||||||
|
|
||||||
|
|||||||
@ -24,80 +24,69 @@ License
|
|||||||
|
|
||||||
\*---------------------------------------------------------------------------*/
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include "SHA1.H"
|
#include "SHA1Digest.H"
|
||||||
#include "IOstreams.H"
|
#include "IOstreams.H"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
//! @cond fileScope
|
||||||
|
const char hexChars[] = "0123456789abcdef";
|
||||||
|
//! @endcond fileScope
|
||||||
|
|
||||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::SHA1::Digest::Digest()
|
Foam::SHA1Digest::SHA1Digest()
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
void Foam::SHA1::Digest::clear()
|
void Foam::SHA1Digest::clear()
|
||||||
{
|
{
|
||||||
memset(v_, '\0', length);
|
memset(v_, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
bool Foam::SHA1::Digest::operator==(const SHA1::Digest& rhs) const
|
bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < length; ++i)
|
for (unsigned i = 0; i < length; ++i)
|
||||||
{
|
{
|
||||||
if (v_[i] != rhs.v_[i])
|
if (v_[i] != rhs.v_[i])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Foam::SHA1::Digest::operator!=(const SHA1::Digest& rhs) const
|
bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const
|
||||||
{
|
{
|
||||||
return !operator==(rhs);
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
|
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1::Digest& dig)
|
Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1Digest& dig)
|
||||||
{
|
{
|
||||||
const char hexChars[] = "0123456789abcdef";
|
|
||||||
|
|
||||||
const unsigned char *v = dig.v_;
|
const unsigned char *v = dig.v_;
|
||||||
for (size_t i=0; i < dig.length; i++)
|
|
||||||
|
for (unsigned i = 0; i < dig.length; ++i)
|
||||||
{
|
{
|
||||||
os.write(hexChars[((v[i] >> 4) & 0xF)]);
|
os.write(hexChars[((v[i] >> 4) & 0xF)]);
|
||||||
os.write(hexChars[(v[i] & 0xF)]);
|
os.write(hexChars[(v[i] & 0xF)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
os.check("Ostream& operator<<(Ostream&, const SHA1::Digest&)");
|
os.check("Ostream& operator<<(Ostream&, const SHA1Digest&)");
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
97
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
Normal file
97
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||||
|
\\/ M anipulation |
|
||||||
|
-------------------------------------------------------------------------------
|
||||||
|
License
|
||||||
|
This file is part of OpenFOAM.
|
||||||
|
|
||||||
|
OpenFOAM is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the
|
||||||
|
Free Software Foundation; either version 2 of the License, or (at your
|
||||||
|
option) any later version.
|
||||||
|
|
||||||
|
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with OpenFOAM; if not, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::SHA1Digest
|
||||||
|
|
||||||
|
Description
|
||||||
|
The SHA1 message digest.
|
||||||
|
|
||||||
|
SeeAlso
|
||||||
|
Foam::SHA1
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
SHA1Digest.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef SHA1Digest_H
|
||||||
|
#define SHA1Digest_H
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
// Forward declaration of classes
|
||||||
|
class Ostream;
|
||||||
|
|
||||||
|
// Forward declaration of friend functions and operators
|
||||||
|
class SHA1;
|
||||||
|
class SHA1Digest;
|
||||||
|
Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||||
|
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class SHA1Digest Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class SHA1Digest
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
friend class SHA1;
|
||||||
|
|
||||||
|
//- The length of the digest contents
|
||||||
|
static const unsigned length = 20;
|
||||||
|
|
||||||
|
//- Construct a zero digest
|
||||||
|
SHA1Digest();
|
||||||
|
|
||||||
|
//- Reset the digest to zero
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
//- Equality operator
|
||||||
|
bool operator==(const SHA1Digest&) const;
|
||||||
|
|
||||||
|
//- Inequality operator
|
||||||
|
bool operator!=(const SHA1Digest&) const;
|
||||||
|
|
||||||
|
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
//- The digest contents
|
||||||
|
unsigned char v_[length];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
||||||
@ -80,13 +80,13 @@ inline Foam::SHA1& Foam::SHA1::append(const char* str)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||||
|
|
||||||
inline bool Foam::SHA1::operator==(const SHA1::Digest& rhs) const
|
inline bool Foam::SHA1::operator==(const SHA1Digest& rhs) const
|
||||||
{
|
{
|
||||||
return this->digest() == rhs;
|
return this->digest() == rhs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline bool Foam::SHA1::operator!=(const SHA1::Digest& rhs) const
|
inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const
|
||||||
{
|
{
|
||||||
return this->digest() != rhs;
|
return this->digest() != rhs;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ inline bool Foam::SHA1::operator!=(const SHA1& rhs) const
|
|||||||
|
|
||||||
|
|
||||||
inline Foam::SHA1::operator
|
inline Foam::SHA1::operator
|
||||||
Foam::SHA1::Digest () const
|
Foam::SHA1Digest () const
|
||||||
{
|
{
|
||||||
return digest();
|
return digest();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user