Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 44 additions & 28 deletions src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Class
Foam::OSHA1stream

Description
An output stream for calculating SHA1 digests.
A Foam::OSstream for calculating SHA-1 digests

SourceFiles
OSHA1stream.C
Expand All @@ -43,24 +43,19 @@ SourceFiles
namespace Foam
{

class osha1stream;
class OSHA1stream;

/*---------------------------------------------------------------------------*\
Class sha1streambuf Declaration
\*---------------------------------------------------------------------------*/

//- A streambuf class for calculating SHA1 digests
class sha1streambuf
:
public std::streambuf
{
// Private data

//- This does all the work and has its own buffering
SHA1 sha1_;
//- The SHA-1 class which processes the strings
SHA1 sha1_;

friend class osha1stream;

public:

Expand All @@ -70,32 +65,56 @@ public:
sha1streambuf()
{}


// Member Functions

// Write
//- Return the SHA-1
SHA1& sha1()
{
return sha1_;
}

//- Process unbuffered
virtual std::streamsize xsputn(const char* str, std::streamsize n)
//- Writes characters from the array pointed to by s
// into the controlled output sequence, until either n characters
// have been written or the end of the output sequence is reached
virtual std::streamsize xsputn(const char* s, std::streamsize n)
{
sha1_.append(str, n);
sha1_.append(s, n);
return n;
}

//- Writes c to the current position of the put pointer (pptr),
// and advances that pointer one position forward.
// If c is EOF, no characters are written and the put pointer
// (pptr) is not advanced.
// Maybe used by xsputn (C++11).
virtual int overflow(int c = EOF)
{
if (c != EOF)
{
const char cc = c;
sha1_.append(&cc, 1);
}

return c;
}
};


/*---------------------------------------------------------------------------*\
Class osha1stream Declaration
\*---------------------------------------------------------------------------*/

//- A basic output stream for calculating SHA1 digests
class osha1stream
:
virtual public std::ios,
public std::ostream
{
// Private data

sha1streambuf sbuf_;
// SHA-1 stream buffer
sha1streambuf sbuf_;


public:

Expand All @@ -107,30 +126,27 @@ public:
std::ostream(&sbuf_)
{}

// Member Functions

// Access
// Member Functions

//- This hides both signatures of std::basic_ios::rdbuf()
sha1streambuf* rdbuf()
//- Return the SHA-1
SHA1& sha1()
{
return &sbuf_;
return sbuf_.sha1();
}

//- Full access to the sha1
SHA1& sha1()
//- Return the stream buffer
sha1streambuf* rdbuf()
{
return sbuf_.sha1_;
return &sbuf_;
}

};


/*---------------------------------------------------------------------------*\
Class OSHA1stream Declaration
\*---------------------------------------------------------------------------*/

//- The output stream for calculating SHA1 digests
class OSHA1stream
:
public OSstream
Expand Down Expand Up @@ -176,14 +192,14 @@ public:

// Access

//- Full access to the sha1
Foam::SHA1& sha1()
//- Return the SHA-1
SHA1& sha1()
{
return dynamic_cast<osha1stream&>(stdStream()).sha1();
}

//- Return SHA1::Digest for the data processed until now
Foam::SHA1Digest digest()
//- Return the SHA-1 digest for the data processed until now
SHA1Digest digest()
{
return sha1().digest();
}
Expand Down