SHA1I.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 OpenFOAM Foundation
9  Copyright (C) 2019-2021 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 \*---------------------------------------------------------------------------*/
28 
29 #include "SHA1.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 {
35  clear();
36 }
37 
38 
39 inline Foam::SHA1::SHA1(const char* str)
40 {
41  clear();
42  append(str);
43 }
44 
45 
46 inline Foam::SHA1::SHA1(const std::string& str)
47 {
48  clear();
49  append(str);
50 }
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 inline Foam::SHA1& Foam::SHA1::append(const char* data, size_t len)
56 {
57  processBytes(data, len);
58  return *this;
59 }
60 
61 
62 inline Foam::SHA1& Foam::SHA1::append(const char* str)
63 {
64  if (str && *str)
65  {
66  processBytes(str, std::char_traits<char>::length(str));
67  }
68  return *this;
69 }
70 
71 
72 inline Foam::SHA1& Foam::SHA1::append(const std::string& str)
73 {
74  processBytes(str.data(), str.length());
75  return *this;
76 }
77 
78 
80 (
81  const std::string& str,
82  size_t pos,
83  size_t len
84 )
85 {
86  if (std::string::npos != pos && pos < str.length())
87  {
88  if (std::string::npos == len || pos + len > str.length())
89  {
90  len = str.length() - pos;
91  }
92 
93  processBytes(str.data() + pos, len);
94  }
95 
96  return *this;
97 }
98 
99 
101 {
102  SHA1Digest dig;
103 
104  if (finalized_)
105  {
106  calcDigest(dig);
107  }
108  else
109  {
110  // Avoid disturbing current data - use a copy
111  SHA1 sha(*this);
112  if (sha.finalize())
113  {
114  sha.calcDigest(dig);
115  }
116  }
117 
118  return dig;
119 }
120 
121 
122 inline std::string Foam::SHA1::str(const bool prefixed) const
123 {
124  return digest().str(prefixed);
125 }
126 
127 
128 inline Foam::Ostream& Foam::SHA1::write(Ostream& os, const bool prefixed) const
129 {
130  return digest().write(os, prefixed);
131 }
132 
133 
134 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
135 
136 inline Foam::SHA1::operator Foam::SHA1Digest() const
137 {
138  return digest();
139 }
140 
141 
142 inline bool Foam::SHA1::operator==(const SHA1& rhs) const
143 {
144  return this->digest() == rhs.digest();
145 }
146 
147 
148 inline bool Foam::SHA1::operator==(const SHA1Digest& dig) const
149 {
150  return this->digest() == dig;
151 }
152 
153 
154 inline bool Foam::SHA1::operator==(const std::string& hexdigits) const
155 {
156  return this->digest() == hexdigits;
157 }
158 
159 
160 inline bool Foam::SHA1::operator==(const char* hexdigits) const
161 {
162  return this->digest() == hexdigits;
163 }
164 
165 
166 inline bool Foam::SHA1::operator!=(const SHA1& rhs) const
167 {
168  return !this->operator==(rhs);
169 }
170 
171 
172 inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const
173 {
174  return !this->operator==(rhs);
175 }
176 
177 
178 inline bool Foam::SHA1::operator!=(const std::string& rhs) const
179 {
180  return !this->operator==(rhs);
181 }
182 
183 
184 inline bool Foam::SHA1::operator!=(const char* rhs) const
185 {
186  return !this->operator==(rhs);
187 }
188 
189 
190 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
191 
193 {
194  return sha.write(os);
195 }
196 
197 
198 // ************************************************************************* //
Foam::SHA1::clear
void clear() noexcept
Reset the hashed data before appending more.
Definition: SHA1.C:315
Foam::SHA1::append
SHA1 & append(const char *str)
Append data for processing.
Definition: SHA1I.H:62
Foam::SHA1::str
std::string str(const bool prefixed=false) const
The digest (40-byte) text representation, optionally with '_' prefix.
Definition: SHA1I.H:122
Foam::SHA1
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:60
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::SHA1::operator==
bool operator==(const SHA1 &rhs) const
Equality operator, compares digests.
Definition: SHA1I.H:142
Foam::operator<<
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::SHA1::write
Ostream & write(Ostream &os, const bool prefixed=false) const
Write digest (40-byte) representation, optionally with '_' prefix.
Definition: SHA1I.H:128
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam::SHA1::digest
SHA1Digest digest() const
Calculate digest from current data.
Definition: SHA1I.H:100
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:60
clear
patchWriters clear()
Foam::SHA1::SHA1
SHA1()
Construct null.
Definition: SHA1I.H:33
Foam::SHA1::operator!=
bool operator!=(const SHA1 &) const
Inequality operator, compares digests.
Definition: SHA1I.H:166
Foam::SHA1::finalize
bool finalize()
Finalized the calculations (normally not needed directly).
Definition: SHA1.C:330
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
SHA1.H
Foam::data
Database for solution data, solver performance and other reduced data.
Definition: data.H:55
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177