SHA1Digest.H 4.72 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
OpenFOAM bot's avatar
OpenFOAM bot committed
5
    \\  /    A nd           | www.openfoam.com
6
     \\/     M anipulation  |
OpenFOAM bot's avatar
OpenFOAM bot committed
7
-------------------------------------------------------------------------------
OpenFOAM bot's avatar
OpenFOAM bot committed
8
9
    Copyright (C) 2011-2016 OpenFOAM Foundation
    Copyright (C) 2019 OpenCFD Ltd.
10
11
12
13
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

14
15
16
17
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
18
19
20
21
22
23
24

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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
30
31
32

Class
    Foam::SHA1Digest

Description
    The SHA1 message digest.

33
See also
34
35
36
37
38
39
40
41
42
43
    Foam::SHA1

SourceFiles
    SHA1Digest.C

\*---------------------------------------------------------------------------*/

#ifndef SHA1Digest_H
#define SHA1Digest_H

44
#include <array>
45
46
#include <string>

47
48
49
50
51
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

52
53
// Forward Declarations
class SHA1;
54
class Istream;
55
class Ostream;
56
57

/*---------------------------------------------------------------------------*\
58
                         Class SHA1Digest Declaration
59
60
61
62
\*---------------------------------------------------------------------------*/

class SHA1Digest
{
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
    // Private Data

        //- The digest contents, which has 20 (uncoded) bytes
        std::array<unsigned char, 20> dig_;


    // Private Member Functions

        //- Pointer to the underlying digest data
        unsigned char* data()
        {
            return dig_.data();
        }

        // Permit SHA1 to calculate the digest
        friend class SHA1;


81
82
public:

83

84
    // Static Data Members
85
86
87
88
89
90
91
92
93
94

        //- A null digest (ie, all zero)
        static const SHA1Digest null;


    // Constructors

        //- Construct a zero digest
        SHA1Digest();

95
96
        //- Read construct a digest
        explicit SHA1Digest(Istream& is);
97
98
99
100
101
102
103
104
105
106
107
108
109


    // Member Functions

        //- Reset the digest to zero
        void clear();

        //- Return true if the digest is empty (ie, all zero).
        bool empty() const;

        //- Return (40-byte) text representation, optionally with '_' prefix
        std::string str(const bool prefixed=false) const;

110
111
112
113
114
115
        //- Read (40-byte) text representation.
        //  Since leading and intermediate underscores are skipped, a '_' can
        //  be prefixed to the text representation to use an unquoted
        //  SHA1Digest without parsing ambiguities as a number.
        Istream& read(Istream& is);

116
        //- Write (40-byte) text representation, optionally with '_' prefix
117
        Ostream& write(Ostream& os, const bool prefixed=false) const;
118
119
120


    // Member Operators
121

122
123
        //- Equality operator
        bool operator==(const SHA1Digest&) const;
124

125
126
127
128
129
        //- Compare to (40-byte) text representation (eg, from sha1sum)
        //  An %empty string is equivalent to
        //  "0000000000000000000000000000000000000000"
        //  The hexdigits may optionally start with a '_' prefix
        bool operator==(const std::string& hexdigits) const;
130

131
132
133
134
135
        //- Compare to (40-byte) text representation (eg, from sha1sum)
        //  A %null or %empty string is equivalent to
        //  "0000000000000000000000000000000000000000"
        //  The hexdigits may optionally start with a '_' prefix
        bool operator==(const char* hexdigits) const;
136

137

138
139
        //- Inequality operator
        bool operator!=(const SHA1Digest&) const;
140

141
142
        //- Inequality operator
        bool operator!=(const std::string& hexdigits) const;
143

144
145
        //- Inequality operator
        bool operator!=(const char* hexdigits) const;
146
};
147
148


149
// IOstream Operators
150

151
152
//- Read (40-byte) text representation (ignoring leading '_' prefix)
Istream& operator>>(Istream&is , SHA1Digest& dig);
153

154
155
//- Write (40-byte) text representation, unquoted and without prefix
Ostream& operator<<(Ostream& os, const SHA1Digest& dig);
156
157
158
159
160
161
162
163
164
165
166


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //