aboutsummaryrefslogtreecommitdiffstats
path: root/libdevcore
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2016-11-14 18:46:43 +0800
committerchriseth <c@ethdev.com>2016-12-01 23:03:59 +0800
commit5789eaa78d0e00f6289101e02f7de5e9decdc7e5 (patch)
tree8964f493235d310baa50806fdff65138054d2439 /libdevcore
parent55a719a79c1ab5b78ea6e1bcb4f27a888494a538 (diff)
downloaddexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar.gz
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar.bz2
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar.lz
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar.xz
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.tar.zst
dexon-solidity-5789eaa78d0e00f6289101e02f7de5e9decdc7e5.zip
Metadata stamp.
Diffstat (limited to 'libdevcore')
-rw-r--r--libdevcore/SwarmHash.cpp12
-rw-r--r--libdevcore/SwarmHash.h5
2 files changed, 10 insertions, 7 deletions
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 <libdevcore/FixedHash.h>
-#include <libdevcore/Common.h>
+
+#include <string>
namespace dev
{
/// Compute the "swarm hash" of @a _data
-h256 swarmHash(bytes const& _data);
+h256 swarmHash(std::string const& _data);
}