mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Add HashVerifier
It is similar to CHashVerifier, but HashVerifier does not need a serialize type and version
This commit is contained in:
parent
d8bdee0fc8
commit
fa961141f7
1 changed files with 34 additions and 0 deletions
34
src/hash.h
34
src/hash.h
|
@ -6,6 +6,7 @@
|
||||||
#ifndef BITCOIN_HASH_H
|
#ifndef BITCOIN_HASH_H
|
||||||
#define BITCOIN_HASH_H
|
#define BITCOIN_HASH_H
|
||||||
|
|
||||||
|
#include <attributes.h>
|
||||||
#include <crypto/common.h>
|
#include <crypto/common.h>
|
||||||
#include <crypto/ripemd160.h>
|
#include <crypto/ripemd160.h>
|
||||||
#include <crypto/sha256.h>
|
#include <crypto/sha256.h>
|
||||||
|
@ -165,6 +166,39 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Reads data from an underlying stream, while hashing the read data. */
|
/** Reads data from an underlying stream, while hashing the read data. */
|
||||||
|
template <typename Source>
|
||||||
|
class HashVerifier : public HashWriter
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
Source& m_source;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit HashVerifier(Source& source LIFETIMEBOUND) : m_source{source} {}
|
||||||
|
|
||||||
|
void read(Span<std::byte> dst)
|
||||||
|
{
|
||||||
|
m_source.read(dst);
|
||||||
|
this->write(dst);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ignore(size_t num_bytes)
|
||||||
|
{
|
||||||
|
std::byte data[1024];
|
||||||
|
while (num_bytes > 0) {
|
||||||
|
size_t now = std::min<size_t>(num_bytes, 1024);
|
||||||
|
read({data, now});
|
||||||
|
num_bytes -= now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
HashVerifier<Source>& operator>>(T&& obj)
|
||||||
|
{
|
||||||
|
::Unserialize(*this, obj);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename Source>
|
template<typename Source>
|
||||||
class CHashVerifier : public CHashWriter
|
class CHashVerifier : public CHashWriter
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue