Commit 28872c44 authored by Mark Olesen's avatar Mark Olesen
Browse files

moved SHA1::Digest class to SHA1Digest to allow forward declarations

parent adfd8254
......@@ -41,7 +41,7 @@ using namespace Foam;
int main(int argc, char * argv[])
{
SHA1 sha;
SHA1::Digest shaDig;
SHA1Digest shaDig;
std::string str("The quick brown fox jumps over the lazy dog");
Info<< shaDig << nl;
......@@ -72,7 +72,7 @@ int main(int argc, char * argv[])
sha.clear();
sha.append(str);
SHA1::Digest shaDig_A = sha;
SHA1Digest shaDig_A = sha;
SHA1 sha_A = sha;
......
......@@ -158,7 +158,7 @@ public:
:
OSstream
(
*(new osha1stream()),
*(new osha1stream),
"OSHA1stream.sinkFile_",
format,
version
......@@ -185,7 +185,7 @@ public:
}
//- Return SHA1::Digest for the data processed until now
Foam::SHA1::Digest digest()
Foam::SHA1Digest 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;
......
......@@ -60,7 +60,6 @@ SourceFiles
#include "HashTable.H"
#include "wordList.H"
#include "className.H"
#include "SHA1.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -70,6 +69,8 @@ namespace Foam
// Forward declaration of friend functions and operators
class regExp;
class dictionary;
class SHA1Digest;
Istream& operator>>(Istream&, dictionary&);
Ostream& operator<<(Ostream&, const dictionary&);
......@@ -212,7 +213,7 @@ public:
label endLineNumber() const;
//- Return the SHA1 digest of the dictionary contents
SHA1::Digest digest() const;
SHA1Digest digest() const;
// Search and lookup
......
......@@ -47,8 +47,8 @@ Description
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
//! @cond fileScope
// The bytes used to pad buffer to the next 64-byte boundary.
// (RFC 1321, 3.1: Step 1)
// The bytes used to pad buffer to the next 64-byte boundary.
// (RFC 1321, 3.1: Step 1)
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
//! @endcond fileScope
......@@ -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])
{
......@@ -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_)
{
......
......@@ -31,10 +31,12 @@ Description
Adapted from the gnulib implementation.
SeeAlso
Foam::SHA1Digest
SourceFiles
SHA1I.H
SHA1.C
SHA1Digest.C
\*---------------------------------------------------------------------------*/
......@@ -45,6 +47,8 @@ SourceFiles
#include <cstddef>
#include <stdint.h> // C++0x uses <cstdint>
#include "SHA1Digest.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......@@ -55,6 +59,7 @@ class Ostream;
// Forward declaration of friend functions and operators
class SHA1;
class SHA1Digest;
Ostream& operator<<(Ostream&, const SHA1&);
......@@ -64,42 +69,6 @@ Ostream& operator<<(Ostream&, const 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
//- Track if the hashsum has been finalized (added count, etc)
......@@ -138,7 +107,7 @@ private:
void processBytes(const void *data, size_t len);
//- Calculate current digest from appended data.
void calcDigest(SHA1::Digest&) const;
void calcDigest(SHA1Digest&) const;
public:
......@@ -172,16 +141,16 @@ public:
bool finalize();
//- Calculate current digest from appended data.
Digest digest() const;
SHA1Digest digest() const;
// Member Operators
//- Equality operator
inline bool operator==(const SHA1::Digest&) const;
inline bool operator==(const SHA1Digest&) const;
//- Inequality operator
inline bool operator!=(const SHA1::Digest&) const;
inline bool operator!=(const SHA1Digest&) const;
//- Equality operator
inline bool operator==(const SHA1&) const;
......@@ -190,8 +159,7 @@ public:
inline bool operator!=(const SHA1&) const;
//- Convert to a digest, calculate current digest from appended data.
inline operator SHA1::Digest() const;
inline operator SHA1Digest() const;
// Friend Functions
......
......@@ -24,80 +24,69 @@ License
\*---------------------------------------------------------------------------*/
#include "SHA1.H"
#include "SHA1Digest.H"
#include "IOstreams.H"
#include <cstring>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
//! @cond fileScope
const char hexChars[] = "0123456789abcdef";
//! @endcond fileScope
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::SHA1::Digest::Digest()
Foam::SHA1Digest::SHA1Digest()
{
clear();
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::SHA1::Digest::clear()
void Foam::SHA1Digest::clear()
{
memset(v_, '\0', length);
memset(v_, 0, length);
}
// * * * * * * * * * * * * * * 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])
{
return false;
}
}
return true;
}
bool Foam::SHA1::Digest::operator!=(const SHA1::Digest& rhs) const
bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const
{
return !operator==(rhs);
}
// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * 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_;
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] & 0xF)]);
}
os.check("Ostream& operator<<(Ostream&, const SHA1::Digest&)");
os.check("Ostream& operator<<(Ostream&, const SHA1Digest&)");
return os;
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 * * * * * * * * * * * * * //
inline bool Foam::SHA1::operator==(const SHA1::Digest& rhs) const
inline bool Foam::SHA1::operator==(const SHA1Digest& rhs) const
{
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;
}
......@@ -105,7 +105,7 @@ inline bool Foam::SHA1::operator!=(const SHA1& rhs) const
inline Foam::SHA1::operator
Foam::SHA1::Digest () const
Foam::SHA1Digest () const
{
return digest();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment