SHA1Digest.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Class
25  Foam::SHA1Digest
26 
27 Description
28  The SHA1 message digest.
29 
30 SeeAlso
31  Foam::SHA1
32 
33 SourceFiles
34  SHA1Digest.C
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #ifndef SHA1Digest_H
39 #define SHA1Digest_H
40 
41 #include <string>
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 // Forward declaration of classes
49 class Istream;
50 class Ostream;
51 
52 // Forward declaration of friend functions and operators
53 class SHA1;
54 class SHA1Digest;
55 Ostream& operator<<(Ostream&, const SHA1Digest&);
56 Istream& operator>>(Istream&, SHA1Digest&);
57 
58 
59 /*---------------------------------------------------------------------------*\
60  Class SHA1Digest Declaration
61 \*---------------------------------------------------------------------------*/
62 
63 class SHA1Digest
64 {
65 public:
66  friend class SHA1;
67 
68  // Static data members
69 
70  //- The length of the (uncoded) digest contents
71  static const unsigned length = 20;
72 
73  //- A null digest (ie, all zero)
74  static const SHA1Digest null;
75 
76 
77  // Constructors
78 
79  //- Construct a zero digest
80  SHA1Digest();
81 
82  //- Construct read a digest
84 
85 
86  // Member Functions
87 
88  //- Reset the digest to zero
89  void clear();
90 
91  //- Return true if the digest is empty (ie, all zero).
92  bool empty() const;
93 
94  //- Return (40-byte) text representation, optionally with '_' prefix
95  std::string str(const bool prefixed=false) const;
96 
97  //- Write (40-byte) text representation, optionally with '_' prefix
98  Ostream& write(Ostream&, const bool prefixed=false) const;
99 
100 
101  // Member Operators
102 
103  //- Equality operator
104  bool operator==(const SHA1Digest&) const;
105 
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;
111 
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;
117 
118 
119  //- Inequality operator
120  bool operator!=(const SHA1Digest&) const;
121 
122  //- Inequality operator
123  bool operator!=(const std::string& hexdigits) const;
124 
125  //- Inequality operator
126  bool operator!=(const char* hexdigits) const;
127 
128 
129 
130 
131  // IOstream Operators
132 
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&);
138 
139  //- Write (40-byte) text representation, unquoted and without prefix
140  friend Ostream& operator<<(Ostream&, const SHA1Digest&);
141 
142 
143 private:
144  // Private data
145 
146  //- The digest contents
147  unsigned char v_[length];
148 
149  //- Read hexadecimal value, ignoring leading or intermediate '_'
150  static unsigned char readHexDigit(Istream&);
151 };
152 
153 
154 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
155 
156 } // End namespace Foam
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 #endif
161 
162 // ************************************************************************* //
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:68
Ostream & write(Ostream &, const bool prefixed=false) const
Write (40-byte) text representation, optionally with &#39;_&#39; prefix.
Definition: SHA1Digest.C:137
void clear()
Reset the digest to zero.
Definition: SHA1Digest.C:92
friend Istream & operator>>(Istream &, SHA1Digest &)
Read (40-byte) text representation.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const unsigned length
The length of the (uncoded) digest contents.
Definition: SHA1Digest.H:70
Ostream & operator<<(Ostream &, const edgeMesh &)
Definition: edgeMeshIO.C:133
Namespace for OpenFOAM.
static const SHA1Digest null
A null digest (ie, all zero)
Definition: SHA1Digest.H:73
bool operator==(const SHA1Digest &) const
Equality operator.
Definition: SHA1Digest.C:157
Istream & operator>>(Istream &, edgeMesh &)
Definition: edgeMeshIO.C:144
bool operator!=(const SHA1Digest &) const
Inequality operator.
Definition: SHA1Digest.C:239
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
SHA1Digest()
Construct a zero digest.
Definition: SHA1Digest.C:78
bool empty() const
Return true if the digest is empty (ie, all zero).
Definition: SHA1Digest.C:98
friend Ostream & operator<<(Ostream &, const SHA1Digest &)
Write (40-byte) text representation, unquoted and without prefix.
The SHA1 message digest.
Definition: SHA1Digest.H:62
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with &#39;_&#39; prefix.
Definition: SHA1Digest.C:112