mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: SHA1Digest : Istream construction
This commit is contained in:
@ -32,7 +32,37 @@ License
|
||||
|
||||
//! @cond fileScope
|
||||
const char hexChars[] = "0123456789abcdef";
|
||||
//! @endcond
|
||||
//! @endcond fileScope
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
unsigned char Foam::SHA1Digest::readHexDigit(Istream& is)
|
||||
{
|
||||
// Takes into account that 'a' (or 'A') is 10
|
||||
static const label alphaOffset = toupper('A') - 10;
|
||||
// Takes into account that '0' is 0
|
||||
static const label zeroOffset = int('0');
|
||||
|
||||
char c = 0;
|
||||
is.read(c);
|
||||
|
||||
if (!isxdigit(c))
|
||||
{
|
||||
FatalIOErrorIn("SHA1Digest::readHexDigit(Istream&)", is)
|
||||
<< "Illegal hex digit: '" << c << "'"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
|
||||
if (isdigit(c))
|
||||
{
|
||||
return int(c) - zeroOffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
return toupper(c) - alphaOffset;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
@ -43,6 +73,12 @@ Foam::SHA1Digest::SHA1Digest()
|
||||
}
|
||||
|
||||
|
||||
Foam::SHA1Digest::SHA1Digest(Istream& is)
|
||||
{
|
||||
is >> *this;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::SHA1Digest::clear()
|
||||
@ -75,6 +111,23 @@ bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const
|
||||
|
||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Istream& Foam::operator>>(Istream& is, SHA1Digest& dig)
|
||||
{
|
||||
unsigned char *v = dig.v_;
|
||||
|
||||
for (unsigned i = 0; i < dig.length; ++i)
|
||||
{
|
||||
unsigned char c1 = SHA1Digest::readHexDigit(is);
|
||||
unsigned char c2 = SHA1Digest::readHexDigit(is);
|
||||
|
||||
v[i] = (c1 << 4) + c2;
|
||||
}
|
||||
|
||||
is.check("Istream& operator>>(Istream&, SHA1Digest&)");
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1Digest& dig)
|
||||
{
|
||||
const unsigned char *v = dig.v_;
|
||||
|
||||
@ -45,11 +45,13 @@ namespace Foam
|
||||
|
||||
// Forward declaration of classes
|
||||
class Ostream;
|
||||
class Istream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class SHA1;
|
||||
class SHA1Digest;
|
||||
Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||
Istream& operator>>(Istream&, SHA1Digest&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
@ -67,6 +69,9 @@ public:
|
||||
//- Construct a zero digest
|
||||
SHA1Digest();
|
||||
|
||||
//- Construct read a digest
|
||||
SHA1Digest(Istream&);
|
||||
|
||||
//- Reset the digest to zero
|
||||
void clear();
|
||||
|
||||
@ -77,11 +82,14 @@ public:
|
||||
bool operator!=(const SHA1Digest&) const;
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||
friend Istream& operator>>(Istream&, SHA1Digest&);
|
||||
|
||||
private:
|
||||
|
||||
//- The digest contents
|
||||
unsigned char v_[length];
|
||||
|
||||
static unsigned char readHexDigit(Istream&);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user