OSHA1stream.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 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::OSHA1stream
29 
30 Description
31  An output stream for calculating SHA1 digests.
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef OSHA1stream_H
36 #define OSHA1stream_H
37 
38 #include "OSstream.H"
39 #include "SHA1.H"
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45 
46 /*---------------------------------------------------------------------------*\
47  Class osha1stream Declaration
48 \*---------------------------------------------------------------------------*/
49 
50 //- A basic output stream for calculating SHA1 digests
51 class osha1stream
52 :
53  virtual public std::ios,
54  public std::ostream
55 {
56  //- A streambuf class for calculating SHA1 digests
57  class sha1buf
58  :
59  public std::streambuf
60  {
61  //- This does all the work and has its own buffering
62  SHA1 sha1_;
63 
64  protected:
65 
66  //- Put sequence of characters
67  virtual std::streamsize xsputn(const char* s, std::streamsize n)
68  {
69  sha1_.append(s, n);
70  return n;
71  }
72 
73  public:
74 
75  //- Construct null
76  sha1buf()
77  {}
78 
79 
80  //- Full access to the sha1
81  inline SHA1& sha1()
82  {
83  return sha1_;
84  }
85  };
86 
87 
88  // Private Data
89 
90  //- Reference to the underlying buffer
91  sha1buf buf_;
92 
93 public:
94 
95  // Constructors
96 
97  //- Construct null
98  osha1stream()
99  :
100  std::ostream(&buf_)
101  {}
102 
103 
104  // Member Functions
105 
106  //- This hides both signatures of std::basic_ios::rdbuf()
107  sha1buf* rdbuf()
108  {
109  return &buf_;
110  }
111 
112  //- Full access to the sha1
113  SHA1& sha1()
114  {
115  return buf_.sha1();
116  }
117 
118 };
119 
120 
121 namespace Detail
122 {
123 
124 /*---------------------------------------------------------------------------*\
125  Class Detail::OSHA1streamAllocator Declaration
126 \*---------------------------------------------------------------------------*/
127 
128 //- Allocator for an osha1stream
130 {
131 protected:
132 
133  // Protected Data
134 
135  typedef osha1stream stream_type;
136 
137  //- The output stream
139 
140 
141  // Constructors
142 
143  //- Construct null
145  :
146  stream_()
147  {}
148 
149 
150 public:
151 
152  // Member Functions
153 
154  //- Full access to the sha1
155  SHA1& sha1()
156  {
157  return stream_.sha1();
158  }
159 
160 
161  //- Return SHA1::Digest for the data processed until now
163  {
164  return stream_.sha1().digest();
165  }
166 
167 
168  //- Clear the SHA1 calculation
169  void reset()
170  {
171  return stream_.sha1().clear();
172  }
173 
174 };
175 
176 } // End namespace Detail
177 
178 
179 /*---------------------------------------------------------------------------*\
180  Class OSHA1stream Declaration
181 \*---------------------------------------------------------------------------*/
182 
183 //- The output stream for calculating SHA1 digests
184 class OSHA1stream
185 :
187  public OSstream
188 {
190 
191  // Private Member Functions
192 
193  //- No copy construct
194  OSHA1stream(const OSHA1stream&) = delete;
195 
196  //- No copy assignment
197  void operator=(const OSHA1stream&) = delete;
198 
199 public:
200 
201  // Constructors
202 
203  //- Construct with an empty digest
205  (
208  )
209  :
210  allocator_type(),
211  OSstream(stream_, "sha1", format, version)
212  {}
213 
214 
215  // Write Functions
216 
217  //- Add (unquoted) string contents.
218  // Ensures that SHA1 of C-string or C++-string content are identical.
219  virtual Ostream& write(const string& str)
220  {
221  return writeQuoted(str, false); // Unquoted!
222  }
223 
224 
225  // Housekeeping
226 
227  //- Deprecated(2017-07) clear the SHA1 calculation
228  // \deprecated(2017-07) - use reset() method
229  void rewind()
230  {
231  sha1().clear();
232  }
233 };
234 
235 
236 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
237 
238 } // End namespace Foam
239 
240 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
241 
242 #endif
243 
244 // ************************************************************************* //
Foam::SHA1::append
SHA1 & append(const char *str)
Append data for processing.
Definition: SHA1I.H:63
s
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< " ";}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){ word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputSpray.H:25
Foam::SHA1
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:60
Foam::OSstream::writeQuoted
virtual Ostream & writeQuoted(const std::string &str, const bool quoted=true)
Write std::string surrounded by quotes.
Definition: OSstream.C:113
Foam::osha1stream::sha1
SHA1 & sha1()
Full access to the sha1.
Definition: OSHA1stream.H:112
Foam::IOstreamOption::format
streamFormat format() const noexcept
Get the current stream format.
Definition: IOstreamOption.H:289
Foam::IOstreamOption::currentVersion
static const versionNumber currentVersion
The current version number (2.0)
Definition: IOstreamOption.H:168
Foam::OSHA1stream::rewind
void rewind()
Deprecated(2017-07) clear the SHA1 calculation.
Definition: OSHA1stream.H:228
Foam::Detail::OSHA1streamAllocator::OSHA1streamAllocator
OSHA1streamAllocator()
Construct null.
Definition: OSHA1stream.H:143
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Detail::OSHA1streamAllocator::sha1
SHA1 & sha1()
Full access to the sha1.
Definition: OSHA1stream.H:154
Foam::IOstreamOption::versionNumber
Representation of a major/minor version number.
Definition: IOstreamOption.H:85
Foam::osha1stream
A basic output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:50
Foam::OSstream::OSstream
OSstream(const OSstream &)=default
Copy construct.
Foam::OSstream
Generic output stream using a standard (STL) stream.
Definition: OSstream.H:54
Foam::OSHA1stream::write
virtual Ostream & write(const string &str)
Add (unquoted) string contents.
Definition: OSHA1stream.H:218
Foam::OSHA1stream
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:183
Foam::IOstreamOption::version
versionNumber version() const noexcept
Get the stream version.
Definition: IOstreamOption.H:341
Foam::IOstreamOption::streamFormat
streamFormat
Data format (ascii | binary)
Definition: IOstreamOption.H:70
Foam::osha1stream::osha1stream
osha1stream()
Construct null.
Definition: OSHA1stream.H:97
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SHA1::digest
SHA1Digest digest() const
Calculate digest from current data.
Definition: SHA1I.H:101
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:60
Foam::Detail::OSHA1streamAllocator::stream_type
osha1stream stream_type
Definition: OSHA1stream.H:134
Foam::IOstreamOption::ASCII
"ascii" (normal default)
Definition: IOstreamOption.H:72
Foam::Detail::OSHA1streamAllocator::stream_
stream_type stream_
The output stream.
Definition: OSHA1stream.H:137
Foam::SHA1::clear
void clear()
Reset the hashed data before appending more.
Definition: SHA1.C:315
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Detail::OSHA1streamAllocator
Allocator for an osha1stream.
Definition: OSHA1stream.H:128
Foam::osha1stream::rdbuf
sha1buf * rdbuf()
This hides both signatures of std::basic_ios::rdbuf()
Definition: OSHA1stream.H:106
SHA1.H
Foam::Detail::OSHA1streamAllocator::reset
void reset()
Clear the SHA1 calculation.
Definition: OSHA1stream.H:168
Foam::Detail::OSHA1streamAllocator::digest
SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:161
OSstream.H