From e549bf8a9afae42fcda805e216a1cde62df195a6 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Thu, 18 Jun 2020 16:32:32 -0700 Subject: Make CHash256 and CHash160 consume Spans --- src/hash.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h index c295568a3e..3289bdee2f 100644 --- a/src/hash.h +++ b/src/hash.h @@ -31,8 +31,8 @@ public: sha.Reset().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash); } - CHash256& Write(const unsigned char *data, size_t len) { - sha.Write(data, len); + CHash256& Write(Span input) { + sha.Write(input.data(), input.size()); return *this; } @@ -55,8 +55,8 @@ public: CRIPEMD160().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(hash); } - CHash160& Write(const unsigned char *data, size_t len) { - sha.Write(data, len); + CHash160& Write(Span input) { + sha.Write(input.data(), input.size()); return *this; } @@ -72,7 +72,7 @@ inline uint256 Hash(const T1 pbegin, const T1 pend) { static const unsigned char pblank[1] = {}; uint256 result; - CHash256().Write(pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])) + CHash256().Write({pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])}) .Finalize((unsigned char*)&result); return result; } @@ -83,8 +83,8 @@ inline uint256 Hash(const T1 p1begin, const T1 p1end, const T2 p2begin, const T2 p2end) { static const unsigned char pblank[1] = {}; uint256 result; - CHash256().Write(p1begin == p1end ? pblank : (const unsigned char*)&p1begin[0], (p1end - p1begin) * sizeof(p1begin[0])) - .Write(p2begin == p2end ? pblank : (const unsigned char*)&p2begin[0], (p2end - p2begin) * sizeof(p2begin[0])) + CHash256().Write({p1begin == p1end ? pblank : (const unsigned char*)&p1begin[0], (p1end - p1begin) * sizeof(p1begin[0])}) + .Write({p2begin == p2end ? pblank : (const unsigned char*)&p2begin[0], (p2end - p2begin) * sizeof(p2begin[0])}) .Finalize((unsigned char*)&result); return result; } @@ -95,7 +95,7 @@ inline uint160 Hash160(const T1 pbegin, const T1 pend) { static unsigned char pblank[1] = {}; uint160 result; - CHash160().Write(pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])) + CHash160().Write({pbegin == pend ? pblank : (const unsigned char*)&pbegin[0], (pend - pbegin) * sizeof(pbegin[0])}) .Finalize((unsigned char*)&result); return result; } @@ -129,7 +129,7 @@ public: int GetVersion() const { return nVersion; } void write(const char *pch, size_t size) { - ctx.Write((const unsigned char*)pch, size); + ctx.Write({(const unsigned char*)pch, size}); } // invalidates the object -- cgit v1.2.3