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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::SHA1Digest
29 
30 Description
31  The SHA1 message digest.
32 
33 See also
34  Foam::SHA1
35 
36 SourceFiles
37  SHA1Digest.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef SHA1Digest_H
42 #define SHA1Digest_H
43 
44 #include <array>
45 #include <string>
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 
49 namespace Foam
50 {
51 
52 // Forward Declarations
53 class SHA1;
54 class Istream;
55 class Ostream;
56 
57 /*---------------------------------------------------------------------------*\
58  Class SHA1Digest Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class SHA1Digest
62 {
63  // Private Data
64 
65  //- The digest contents, which has 20 (uncoded) bytes
66  std::array<unsigned char, 20> dig_;
67 
68 
69  // Private Member Functions
70 
71  //- Pointer to the underlying digest data
72  unsigned char* data()
73  {
74  return dig_.data();
75  }
76 
77  // Permit SHA1 to calculate the digest
78  friend class SHA1;
79 
80 
81 public:
82 
83 
84  // Static Data Members
85 
86  //- A null digest (ie, all zero)
87  static const SHA1Digest null;
88 
89 
90  // Constructors
91 
92  //- Construct a zero digest
93  SHA1Digest();
94 
95  //- Read construct a digest
96  explicit SHA1Digest(Istream& is);
97 
98 
99  // Member Functions
100 
101  //- Reset the digest to zero
102  void clear();
103 
104  //- Return true if the digest is empty (ie, all zero).
105  bool empty() const;
106 
107  //- Return (40-byte) text representation, optionally with '_' prefix
108  std::string str(const bool prefixed=false) const;
109 
110  //- Read (40-byte) text representation.
111  // Since leading and intermediate underscores are skipped, a '_' can
112  // be prefixed to the text representation to use an unquoted
113  // SHA1Digest without parsing ambiguities as a number.
114  Istream& read(Istream& is);
115 
116  //- Write (40-byte) text representation, optionally with '_' prefix
117  Ostream& write(Ostream& os, const bool prefixed=false) const;
118 
119 
120  // Member Operators
121 
122  //- Equality operator
123  bool operator==(const SHA1Digest&) const;
124 
125  //- Compare to (40-byte) text representation (eg, from sha1sum)
126  // An %empty string is equivalent to
127  // "0000000000000000000000000000000000000000"
128  // The hexdigits may optionally start with a '_' prefix
129  bool operator==(const std::string& hexdigits) const;
130 
131  //- Compare to (40-byte) text representation (eg, from sha1sum)
132  // A %null or %empty string is equivalent to
133  // "0000000000000000000000000000000000000000"
134  // The hexdigits may optionally start with a '_' prefix
135  bool operator==(const char* hexdigits) const;
136 
137 
138  //- Inequality operator
139  bool operator!=(const SHA1Digest&) const;
140 
141  //- Inequality operator
142  bool operator!=(const std::string& hexdigits) const;
143 
144  //- Inequality operator
145  bool operator!=(const char* hexdigits) const;
146 };
147 
148 
149 // IOstream Operators
150 
151 //- Read (40-byte) text representation (ignoring leading '_' prefix)
153 
154 //- Write (40-byte) text representation, unquoted and without prefix
155 Ostream& operator<<(Ostream& os, const SHA1Digest& dig);
156 
157 
158 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
159 
160 } // End namespace Foam
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
165 
166 // ************************************************************************* //
Foam::SHA1Digest::SHA1Digest
SHA1Digest()
Construct a zero digest.
Definition: SHA1Digest.C:81
Foam::SHA1Digest::operator==
bool operator==(const SHA1Digest &) const
Equality operator.
Definition: SHA1Digest.C:176
Foam::SHA1
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:60
Foam::SHA1Digest::clear
void clear()
Reset the digest to zero.
Definition: SHA1Digest.C:96
Foam::operator>>
Istream & operator>>(Istream &, directionInfo &)
Definition: directionInfo.C:230
Foam::SHA1Digest::empty
bool empty() const
Return true if the digest is empty (ie, all zero).
Definition: SHA1Digest.C:102
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::SHA1Digest::write
Ostream & write(Ostream &os, const bool prefixed=false) const
Write (40-byte) text representation, optionally with '_' prefix.
Definition: SHA1Digest.C:156
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
os
OBJstream os(runTime.globalPath()/outputName)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:60
Foam::SHA1Digest::operator!=
bool operator!=(const SHA1Digest &) const
Inequality operator.
Definition: SHA1Digest.C:250
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::SHA1Digest::read
Istream & read(Istream &is)
Read (40-byte) text representation.
Definition: SHA1Digest.C:141
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::SHA1Digest::str
std::string str(const bool prefixed=false) const
Return (40-byte) text representation, optionally with '_' prefix.
Definition: SHA1Digest.C:116