36 static const char hexChars[] =
"0123456789abcdef";
42 unsigned char Foam::SHA1Digest::readHexDigit(Istream& is)
45 static const int alphaOffset = toupper(
'A') - 10;
47 static const int zeroOffset = int(
'0');
61 <<
"Illegal hex digit: '" << c <<
"'" 67 return int(c) - zeroOffset;
71 return toupper(c) - alphaOffset;
100 for (
unsigned i = 0; i <
length; ++i)
127 for (
unsigned i = 0; i <
length; ++i)
129 buf[nChar++] = hexChars[((v_[i] >> 4) & 0xF)];
130 buf[nChar++] = hexChars[(v_[i] & 0xF)];
144 for (
unsigned i = 0; i <
length; ++i)
146 os.
write(hexChars[((v_[i] >> 4) & 0xF)]);
147 os.
write(hexChars[(v_[i] & 0xF)]);
150 os.
check(
"SHA1Digest::write(Ostream&, const bool)");
159 for (
unsigned i = 0; i <
length; ++i)
161 if (v_[i] != rhs.v_[i])
174 if (hexdigits.empty())
181 if (hexdigits[0] ==
'_')
187 if (hexdigits.size() != charI +
length*2)
192 for (
unsigned i = 0; i <
length; ++i)
194 const char c1 = hexChars[((v_[i] >> 4) & 0xF)];
195 const char c2 = hexChars[(v_[i] & 0xF)];
197 if (c1 != hexdigits[charI++])
return false;
198 if (c2 != hexdigits[charI++])
return false;
208 if (!hexdigits || !*hexdigits)
215 if (hexdigits[0] ==
'_')
221 if (strlen(hexdigits) != charI +
length*2)
226 for (
unsigned i = 0; i <
length; ++i)
228 const char c1 = hexChars[((v_[i] >> 4) & 0xF)];
229 const char c2 = hexChars[(v_[i] & 0xF)];
231 if (c1 != hexdigits[charI++])
return false;
232 if (c2 != hexdigits[charI++])
return false;
261 unsigned char *v = dig.v_;
263 for (
unsigned i = 0; i < dig.
length; ++i)
265 unsigned char c1 = SHA1Digest::readHexDigit(is);
266 unsigned char c2 = SHA1Digest::readHexDigit(is);
268 v[i] = (c1 << 4) + c2;
271 is.
check(
"Istream& operator>>(Istream&, SHA1Digest&)");
278 return dig.
write(os);
errorManipArg< error, int > exit(error &err, const int errNo=1)
virtual bool check(const char *operation) const
Check IOstream status for given operation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
const dimensionedScalar c2
Second radiation constant: default SI units: [m K].
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Ostream & write(Ostream &, const bool prefixed=false) const
Write (40-byte) text representation, optionally with '_' prefix.
static const unsigned length
The length of the (uncoded) digest contents.
Istream & operator>>(Istream &, directionInfo &)
SHA1Digest()
Construct a zero digest.
bool operator!=(const SHA1Digest &) const
Inequality operator.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
bool empty() const
Return true if the digest is empty (ie, all zero).
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
void clear()
Reset the digest to zero.
Ostream & operator<<(Ostream &, const ensightPart &)
const dimensionedScalar c1
First radiation constant: default SI units: [W/m^2].
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with '_' prefix.
bool operator==(const SHA1Digest &) const
Equality operator.
virtual Ostream & write(const token &)=0
Write next token to stream.
static const SHA1Digest null
A null digest (ie, all zero)