SHA1I.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 \*---------------------------------------------------------------------------*/
25 
26 #include "SHA1.H"
27 #include <cstring>
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
32 {
33  clear();
34 }
35 
36 
37 inline Foam::SHA1::SHA1(const std::string& str)
38 {
39  clear();
40  append(str);
41 }
42 
43 
44 inline Foam::SHA1::SHA1(const char* str)
45 {
46  clear();
47  append(str);
48 }
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 inline Foam::SHA1& Foam::SHA1::append(const char* data, size_t len)
54 {
55  processBytes(data, len);
56  return *this;
57 }
58 
59 
60 inline Foam::SHA1& Foam::SHA1::append(const std::string& str)
61 {
62  processBytes(str.data(), str.size());
63  return *this;
64 }
65 
66 
67 inline Foam::SHA1& Foam::SHA1::append(const char* str)
68 {
69  if (str)
70  {
71  processBytes(str, strlen(str));
72  }
73  return *this;
74 }
75 
76 
77 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
78 
79 inline bool Foam::SHA1::operator==(const SHA1& rhs) const
80 {
81  return this->digest() == rhs.digest();
82 }
83 
84 
85 inline bool Foam::SHA1::operator==(const SHA1Digest& rhs) const
86 {
87  return this->digest() == rhs;
88 }
89 
90 
91 inline bool Foam::SHA1::operator==(const std::string& hexdigits) const
92 {
93  return this->digest() == hexdigits;
94 }
95 
96 
97 inline bool Foam::SHA1::operator==(const char* hexdigits) const
98 {
99  return this->digest() == hexdigits;
100 }
101 
102 
103 inline bool Foam::SHA1::operator!=(const SHA1& rhs) const
104 {
105  return !this->operator==(rhs);
106 }
107 
108 
109 inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const
110 {
111  return !this->operator==(rhs);
112 }
113 
114 
115 inline bool Foam::SHA1::operator!=(const std::string& rhs) const
116 {
117  return !this->operator==(rhs);
118 }
119 
120 
121 inline bool Foam::SHA1::operator!=(const char* rhs) const
122 {
123  return !this->operator==(rhs);
124 }
125 
126 
127 inline Foam::SHA1::operator Foam::SHA1Digest() const
128 {
129  return digest();
130 }
131 
132 
133 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
134 
135 inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha)
136 {
137  return os << sha.digest();
138 }
139 
140 
141 // ************************************************************************* //
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
The SHA1 message digest.
Definition: SHA1Digest.H:63
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
Definition: SHA1.H:69
SHA1 & append(const char *data, size_t len)
Append data for processing.
Definition: SHA1I.H:53
bool operator==(const SHA1 &) const
Equality operator, compares digests.
Definition: SHA1I.H:79
bool operator!=(const SHA1 &) const
Inequality operator, compares digests.
Definition: SHA1I.H:103
SHA1()
Construct null.
Definition: SHA1I.H:31
void clear()
Reset the hashed data before appending more.
Definition: SHA1.C:339
SHA1Digest digest() const
Calculate current digest from appended data.
Definition: SHA1.C:393
Database for solution and other reduced data.
Definition: data.H:54
tUEqn clear()
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Ostream & operator<<(Ostream &, const ensightPart &)