MCPcopy Create free account
hub / github.com/ElementsProject/elements / CHashVerifier

Class CHashVerifier

src/hash.h:158–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156/** Reads data from an underlying stream, while hashing the read data. */
157template<typename Source>
158class CHashVerifier : public CHashWriter
159{
160private:
161 Source* source;
162
163public:
164 explicit CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {}
165
166 void read(Span<std::byte> dst)
167 {
168 source->read(dst);
169 this->write(dst);
170 }
171
172 void ignore(size_t nSize)
173 {
174 std::byte data[1024];
175 while (nSize > 0) {
176 size_t now = std::min<size_t>(nSize, 1024);
177 read({data, now});
178 nSize -= now;
179 }
180 }
181
182 template<typename T>
183 CHashVerifier<Source>& operator>>(T&& obj)
184 {
185 // Unserialize from this stream
186 ::Unserialize(*this, obj);
187 return (*this);
188 }
189};
190
191/** Writes data to an underlying source stream, while hashing the written data. */
192template <typename Source>

Callers

nothing calls this directly

Calls 1

UnserializeFunction · 0.85

Tested by

no test coverage detected