SHA1Digest.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 See also
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 
66 public:
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 private:
78 
79  // Private Data
80 
81  //- The digest contents
82  unsigned char v_[length];
83 
84  //- Read hexadecimal value, ignoring leading or intermediate '_'
85  static unsigned char readHexDigit(Istream&);
86 
87 
88 public:
89 
90  friend class SHA1;
91 
92 
93  // Constructors
94 
95  //- Construct a zero digest
96  SHA1Digest();
97 
98  //- Construct read a digest
100 
101 
102  // Member Functions
103 
104  //- Reset the digest to zero
105  void clear();
106 
107  //- Return true if the digest is empty (ie, all zero).
108  bool empty() const;
109 
110  //- Return (40-byte) text representation, optionally with '_' prefix
111  std::string str(const bool prefixed=false) const;
112 
113  //- Write (40-byte) text representation, optionally with '_' prefix
114  Ostream& write(Ostream&, const bool prefixed=false) const;
115 
116 
117  // Member Operators
118 
119  //- Equality operator
120  bool operator==(const SHA1Digest&) const;
121 
122  //- Compare to (40-byte) text representation (eg, from sha1sum)
123  // An %empty string is equivalent to
124  // "0000000000000000000000000000000000000000"
125  // The hexdigits may optionally start with a '_' prefix
126  bool operator==(const std::string& hexdigits) const;
127 
128  //- Compare to (40-byte) text representation (eg, from sha1sum)
129  // A %null or %empty string is equivalent to
130  // "0000000000000000000000000000000000000000"
131  // The hexdigits may optionally start with a '_' prefix
132  bool operator==(const char* hexdigits) const;
133 
134 
135  //- Inequality operator
136  bool operator!=(const SHA1Digest&) const;
137 
138  //- Inequality operator
139  bool operator!=(const std::string& hexdigits) const;
140 
141  //- Inequality operator
142  bool operator!=(const char* hexdigits) const;
143 
144 
145 
146 
147  // IOstream Operators
148 
149  //- Read (40-byte) text representation
150  // Since leading and intermediate underscores are skipped, a '_' can
151  // be prefixed to the text representation to use an unquoted
152  // SHA1Digest without parsing ambiguities as a number.
153  friend Istream& operator>>(Istream&, SHA1Digest&);
154 
155  //- Write (40-byte) text representation, unquoted and without prefix
156  friend Ostream& operator<<(Ostream&, const SHA1Digest&);
157 };
158 
159 
160 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
161 
162 } // End namespace Foam
163 
164 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
165 
166 #endif
167 
168 // ************************************************************************* //
friend Ostream & operator<<(Ostream &, const SHA1Digest &)
Write (40-byte) text representation, unquoted and without prefix.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
The SHA1 message digest.
Definition: SHA1Digest.H:62
Ostream & write(Ostream &, const bool prefixed=false) const
Write (40-byte) text representation, optionally with &#39;_&#39; prefix.
Definition: SHA1Digest.C:137
static const unsigned length
The length of the (uncoded) digest contents.
Definition: SHA1Digest.H:70
Istream & operator>>(Istream &, directionInfo &)
SHA1Digest()
Construct a zero digest.
Definition: SHA1Digest.C:78
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
bool empty() const
Return true if the digest is empty (ie, all zero).
Definition: SHA1Digest.C:98
friend Istream & operator>>(Istream &, SHA1Digest &)
Read (40-byte) text representation.
void clear()
Reset the digest to zero.
Definition: SHA1Digest.C:92
Ostream & operator<<(Ostream &, const ensightPart &)
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with &#39;_&#39; prefix.
Definition: SHA1Digest.C:112
bool operator==(const SHA1Digest &) const
Equality operator.
Definition: SHA1Digest.C:157
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:68
static const SHA1Digest null
A null digest (ie, all zero)
Definition: SHA1Digest.H:73
Namespace for OpenFOAM.