From 5789eaa78d0e00f6289101e02f7de5e9decdc7e5 Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 14 Nov 2016 11:46:43 +0100 Subject: Metadata stamp. --- libdevcore/SwarmHash.cpp | 12 +++++++----- libdevcore/SwarmHash.h | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'libdevcore') diff --git a/libdevcore/SwarmHash.cpp b/libdevcore/SwarmHash.cpp index e7b844eb..aa98eafd 100644 --- a/libdevcore/SwarmHash.cpp +++ b/libdevcore/SwarmHash.cpp @@ -38,13 +38,14 @@ h256 swarmHashSimple(bytesConstRef _data, size_t _size) return keccak256(toLittleEndian(_size) + _data.toBytes()); } -h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length) +h256 swarmHashIntermediate(string const& _input, size_t _offset, size_t _length) { + bytesConstRef ref; + bytes innerNodes; if (_length <= 0x1000) - return swarmHashSimple(bytesConstRef(_input.data() + _offset, _length), _length); + ref = bytesConstRef(_input).cropped(_offset, _length); else { - bytes innerNodes; size_t maxRepresentedSize = 0x1000; while (maxRepresentedSize * (0x1000 / 32) < _length) maxRepresentedSize *= (0x1000 / 32); @@ -53,11 +54,12 @@ h256 swarmHashIntermediate(bytes const& _input, size_t _offset, size_t _length) size_t size = std::min(maxRepresentedSize, _length - i); innerNodes += swarmHashIntermediate(_input, _offset + i, size).asBytes(); } - return swarmHashSimple(bytesConstRef(&innerNodes), _length); + ref = bytesConstRef(&innerNodes); } + return swarmHashSimple(ref, _length); } -h256 dev::swarmHash(bytes const& _input) +h256 dev::swarmHash(string const& _input) { return swarmHashIntermediate(_input, 0, _input.size()); } diff --git a/libdevcore/SwarmHash.h b/libdevcore/SwarmHash.h index 925509ab..f474ce11 100644 --- a/libdevcore/SwarmHash.h +++ b/libdevcore/SwarmHash.h @@ -20,12 +20,13 @@ #pragma once #include -#include + +#include namespace dev { /// Compute the "swarm hash" of @a _data -h256 swarmHash(bytes const& _data); +h256 swarmHash(std::string const& _data); } -- cgit v1.2.3