FreeFOAM The Cross-Platform CFD Toolkit
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 | Copyright (C) 1991-2010 OpenCFD Ltd.
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 // * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
52 
53 
54 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
55 
56 inline Foam::SHA1& Foam::SHA1::append(const char* data, size_t len)
57 {
58  processBytes(data, len);
59  return *this;
60 }
61 
62 
63 inline Foam::SHA1& Foam::SHA1::append(const std::string& str)
64 {
65  processBytes(str.data(), str.size());
66  return *this;
67 }
68 
69 
70 inline Foam::SHA1& Foam::SHA1::append(const char* str)
71 {
72  if (str)
73  {
74  processBytes(str, strlen(str));
75  }
76  return *this;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
81 
82 inline bool Foam::SHA1::operator==(const SHA1Digest& rhs) const
83 {
84  return this->digest() == rhs;
85 }
86 
87 
88 inline bool Foam::SHA1::operator!=(const SHA1Digest& rhs) const
89 {
90  return this->digest() != rhs;
91 }
92 
93 
94 inline bool Foam::SHA1::operator==(const SHA1& rhs) const
95 {
96  return digest() == rhs.digest();
97 }
98 
99 
100 inline bool Foam::SHA1::operator!=(const SHA1& rhs) const
101 {
102  return digest() != rhs.digest();
103 }
104 
105 
106 inline Foam::SHA1::operator
107 Foam::SHA1Digest () const
108 {
109  return digest();
110 }
111 
112 
113 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
114 
115 
116 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
117 
118 
119 // * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
120 
121 
122 // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
123 
124 inline Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1& sha)
125 {
126  return os << sha.digest();
127 }
128 
129 
130 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
131 
132 
133 // ************************ vim: set sw=4 sts=4 et: ************************ //