Test-SHA1.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2015 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 Application
25  testSHA1
26 
27 Description
28 
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "OSHA1stream.H"
33 #include "IStringStream.H"
34 #include "dictionary.H"
35 
36 using namespace Foam;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 int main(int argc, char * argv[])
41 {
42  SHA1 sha;
43  SHA1Digest shaDig;
44 
45  std::string str("The quick brown fox jumps over the lazy dog");
46  Info<< shaDig << nl;
47  Info<< SHA1("The quick brown fox jumps over the lazy dog") << nl;
48 
49  sha.append("The quick brown fox jumps over the lazy dog");
50  Info<< sha << nl;
51 
52  sha.clear();
53  sha.append("The quick brown fox jumps over the lazy dog");
54  shaDig = sha;
55 
56  sha.append("\n");
57  Info<< sha << nl;
58  Info<< shaDig << nl;
59 
60  if (sha == shaDig)
61  {
62  Info<<"SHA1 digests are identical\n";
63  }
64  else
65  {
66  Info<<"SHA1 digests are different\n";
67  }
68  Info<<"lhs:" << sha << " rhs:" << shaDig << endl;
69 
70  // start over:
71  sha.clear();
72  sha.append(str);
73 
74  SHA1 sha_A = sha;
75 
76  sha.append("\n");
77 
78  Info<< "digest1: " << sha_A << nl;
79  Info<< "digest2: " << sha << nl;
80 
81  // start over:
82  sha.clear();
83  sha.append("\"");
84  sha.append(str);
85  sha.append("\"");
86 
87  Info<< "digest3: " << sha << nl;
88 
89  // try the output buffer interface
90  {
91  OSHA1stream os;
92 
93  os << str;
94  Info<< os.digest() << endl;
95 
96  os << str;
97  Info<< os.digest() << endl;
98 
99  os.rewind();
100  os << "The quick brown fox jumps over the lazy dog";
101  Info<< os.digest() << endl;
102 
103  }
104 
105  {
107  (
109  (
110  "parent { Default_Boundary_Region { type zeroGradient; } }"
111  "inlet_1 { value inlet_1; }"
112  "inlet_2 { value inlet_2; }"
113  "inlet_3 { value inlet_3; }"
114  "\"inlet_.*\" { value XXX; }"
115  ) ()
116  );
117 
118  Info<< "dict:" << endl;
119  dict.write(Info, false);
120 
121  dictionary dict2(dict);
122 
123  OSHA1stream os;
124  dict.write(os, false);
125  Info<< os.digest() << endl;
126 
127  Info<< dict2.digest() << endl;
128  }
129 
130 
131  return 0;
132 }
Foam::SHA1::append
SHA1 & append(const char *data, size_t len)
Append data for processing.
Definition: SHA1I.H:53
main
int main(int argc, char *argv[])
Definition: Test-SHA1.C:37
Foam::SHA1
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:68
Foam::OSHA1stream::rewind
void rewind()
Clear the SHA1 calculation.
Definition: OSHA1stream.H:193
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IStringStream.H
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::OSHA1stream
The output stream for calculating SHA1 digests.
Definition: OSHA1stream.H:133
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::SHA1Digest
The SHA1 message digest.
Definition: SHA1Digest.H:62
dictionary.H
OSHA1stream.H
Foam::SHA1::clear
void clear()
Reset the hashed data before appending more.
Definition: SHA1.C:341
Foam::dictionary::digest
SHA1Digest digest() const
Return the SHA1 digest of the dictionary contents.
Definition: dictionary.C:270
Foam::OSHA1stream::digest
Foam::SHA1Digest digest()
Return SHA1::Digest for the data processed until now.
Definition: OSHA1stream.H:185
Foam::dictionary::write
void write(Ostream &, const bool subDict=true) const
Write dictionary, normally with sub-dictionary formatting.
Definition: dictionaryIO.C:173