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