1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 The SHA1 message digest.
36 \*---------------------------------------------------------------------------*/
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // Forward declaration of classes
52 // Forward declaration of friend functions and operators
55 Ostream& operator<<(Ostream&, const SHA1Digest&);
56 Istream& operator>>(Istream&, SHA1Digest&);
59 /*---------------------------------------------------------------------------*\
60 Class SHA1Digest Declaration
61 \*---------------------------------------------------------------------------*/
68 // Static data members
70 //- The length of the (uncoded) digest contents
71 static const unsigned length = 20;
73 //- A null digest (ie, all zero)
74 static const SHA1Digest null;
79 //- Construct a zero digest
82 //- Construct read a digest
88 //- Reset the digest to zero
91 //- Return true if the digest is empty (ie, all zero).
94 //- Return (40-byte) text representation, optionally with '_' prefix
95 std::string str(const bool prefixed=false) const;
97 //- Write (40-byte) text representation, optionally with '_' prefix
98 Ostream& write(Ostream&, const bool prefixed=false) const;
103 //- Equality operator
104 bool operator==(const SHA1Digest&) const;
106 //- Compare to (40-byte) text representation (eg, from sha1sum)
107 // An %empty string is equivalent to
108 // "0000000000000000000000000000000000000000"
109 // The hexdigits may optionally start with a '_' prefix
110 bool operator==(const std::string& hexdigits) const;
112 //- Compare to (40-byte) text representation (eg, from sha1sum)
113 // A %null or %empty string is equivalent to
114 // "0000000000000000000000000000000000000000"
115 // The hexdigits may optionally start with a '_' prefix
116 bool operator==(const char* hexdigits) const;
119 //- Inequality operator
120 bool operator!=(const SHA1Digest&) const;
122 //- Inequality operator
123 bool operator!=(const std::string& hexdigits) const;
125 //- Inequality operator
126 bool operator!=(const char* hexdigits) const;
131 // IOstream Operators
133 //- Read (40-byte) text representation
134 // Since leading and intermediate underscores are skipped, a '_' can
135 // be prefixed to the text representation to use an unquoted
136 // SHA1Digest without parsing ambiguities as a number.
137 friend Istream& operator>>(Istream&, SHA1Digest&);
139 //- Write (40-byte) text representation, unquoted and without prefix
140 friend Ostream& operator<<(Ostream&, const SHA1Digest&);
146 //- The digest contents
147 unsigned char v_[length];
149 //- Read hexadecimal value, ignoring leading or intermediate '_'
150 static unsigned char readHexDigit(Istream&);
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 } // End namespace Foam
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
162 // ************************************************************************* //