File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 6
6
#ifndef BITCOIN_HASH_H
7
7
#define BITCOIN_HASH_H
8
8
9
+ #include < attributes.h>
9
10
#include < crypto/common.h>
10
11
#include < crypto/ripemd160.h>
11
12
#include < crypto/sha256.h>
@@ -165,6 +166,39 @@ class CHashWriter : public HashWriter
165
166
};
166
167
167
168
/* * Reads data from an underlying stream, while hashing the read data. */
169
+ template <typename Source>
170
+ class HashVerifier : public HashWriter
171
+ {
172
+ private:
173
+ Source& m_source;
174
+
175
+ public:
176
+ explicit HashVerifier (Source& source LIFETIMEBOUND) : m_source{source} {}
177
+
178
+ void read (Span<std::byte> dst)
179
+ {
180
+ m_source.read (dst);
181
+ this ->write (dst);
182
+ }
183
+
184
+ void ignore (size_t num_bytes)
185
+ {
186
+ std::byte data[1024 ];
187
+ while (num_bytes > 0 ) {
188
+ size_t now = std::min<size_t >(num_bytes, 1024 );
189
+ read ({data, now});
190
+ num_bytes -= now;
191
+ }
192
+ }
193
+
194
+ template <typename T>
195
+ HashVerifier<Source>& operator >>(T&& obj)
196
+ {
197
+ ::Unserialize (*this , obj);
198
+ return *this ;
199
+ }
200
+ };
201
+
168
202
template <typename Source>
169
203
class CHashVerifier : public CHashWriter
170
204
{
You can’t perform that action at this time.
0 commit comments