mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-01 00:34:01 +02:00
Make Hash[160] consume range-like objects
This commit is contained in:
@@ -54,9 +54,8 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
(void)sha512.Write(data.data(), data.size());
|
||||
(void)sip_hasher.Write(data.data(), data.size());
|
||||
|
||||
(void)Hash(data.begin(), data.end());
|
||||
(void)Hash(data);
|
||||
(void)Hash160(data);
|
||||
(void)Hash160(data.begin(), data.end());
|
||||
(void)sha512.Size();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
assert(negated_key == key);
|
||||
}
|
||||
|
||||
const uint256 random_uint256 = Hash(buffer.begin(), buffer.end());
|
||||
const uint256 random_uint256 = Hash(buffer);
|
||||
|
||||
{
|
||||
CKey child_key;
|
||||
|
||||
@@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(key_test1)
|
||||
for (int n=0; n<16; n++)
|
||||
{
|
||||
std::string strMsg = strprintf("Very secret message %i: 11", n);
|
||||
uint256 hashMsg = Hash(strMsg.begin(), strMsg.end());
|
||||
uint256 hashMsg = Hash(strMsg);
|
||||
|
||||
// normal signatures
|
||||
|
||||
@@ -134,7 +134,7 @@ BOOST_AUTO_TEST_CASE(key_test1)
|
||||
|
||||
std::vector<unsigned char> detsig, detsigc;
|
||||
std::string strMsg = "Very deterministic message";
|
||||
uint256 hashMsg = Hash(strMsg.begin(), strMsg.end());
|
||||
uint256 hashMsg = Hash(strMsg);
|
||||
BOOST_CHECK(key1.Sign(hashMsg, detsig));
|
||||
BOOST_CHECK(key1C.Sign(hashMsg, detsigc));
|
||||
BOOST_CHECK(detsig == detsigc);
|
||||
@@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
|
||||
// When entropy is specified, we should see at least one high R signature within 20 signatures
|
||||
CKey key = DecodeSecret(strSecret1);
|
||||
std::string msg = "A message to be signed";
|
||||
uint256 msg_hash = Hash(msg.begin(), msg.end());
|
||||
uint256 msg_hash = Hash(msg);
|
||||
std::vector<unsigned char> sig;
|
||||
bool found = false;
|
||||
|
||||
@@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
sig.clear();
|
||||
std::string msg = "A message to be signed" + ToString(i);
|
||||
msg_hash = Hash(msg.begin(), msg.end());
|
||||
msg_hash = Hash(msg);
|
||||
BOOST_CHECK(key.Sign(msg_hash, sig));
|
||||
found = sig[3] == 0x20;
|
||||
BOOST_CHECK(sig.size() <= 70);
|
||||
|
||||
@@ -13,9 +13,9 @@ static uint256 ComputeMerkleRootFromBranch(const uint256& leaf, const std::vecto
|
||||
uint256 hash = leaf;
|
||||
for (std::vector<uint256>::const_iterator it = vMerkleBranch.begin(); it != vMerkleBranch.end(); ++it) {
|
||||
if (nIndex & 1) {
|
||||
hash = Hash(it->begin(), it->end(), hash.begin(), hash.end());
|
||||
hash = Hash(*it, hash);
|
||||
} else {
|
||||
hash = Hash(hash.begin(), hash.end(), it->begin(), it->end());
|
||||
hash = Hash(hash, *it);
|
||||
}
|
||||
nIndex >>= 1;
|
||||
}
|
||||
@@ -144,8 +144,7 @@ static uint256 BlockBuildMerkleTree(const CBlock& block, bool* fMutated, std::ve
|
||||
// Two identical hashes at the end of the list at a particular level.
|
||||
mutated = true;
|
||||
}
|
||||
vMerkleTree.push_back(Hash(vMerkleTree[j+i].begin(), vMerkleTree[j+i].end(),
|
||||
vMerkleTree[j+i2].begin(), vMerkleTree[j+i2].end()));
|
||||
vMerkleTree.push_back(Hash(vMerkleTree[j+i], vMerkleTree[j+i2]));
|
||||
}
|
||||
j += nSize;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(floats)
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
ss << float(i);
|
||||
}
|
||||
BOOST_CHECK(Hash(ss.begin(), ss.end()) == uint256S("8e8b4cf3e4df8b332057e3e23af42ebc663b61e0495d5e7e32d85099d7f3fe0c"));
|
||||
BOOST_CHECK(Hash(ss) == uint256S("8e8b4cf3e4df8b332057e3e23af42ebc663b61e0495d5e7e32d85099d7f3fe0c"));
|
||||
|
||||
// decode
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
@@ -162,7 +162,7 @@ BOOST_AUTO_TEST_CASE(doubles)
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
ss << double(i);
|
||||
}
|
||||
BOOST_CHECK(Hash(ss.begin(), ss.end()) == uint256S("43d0c82591953c4eafe114590d392676a01585d25b25d433557f0d7878b23f96"));
|
||||
BOOST_CHECK(Hash(ss) == uint256S("43d0c82591953c4eafe114590d392676a01585d25b25d433557f0d7878b23f96"));
|
||||
|
||||
// decode
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
|
||||
@@ -2186,8 +2186,8 @@ BOOST_AUTO_TEST_CASE(message_hash)
|
||||
std::string(1, (char)unsigned_tx.length()) +
|
||||
unsigned_tx;
|
||||
|
||||
const uint256 signature_hash = Hash(unsigned_tx.begin(), unsigned_tx.end());
|
||||
const uint256 message_hash1 = Hash(prefixed_message.begin(), prefixed_message.end());
|
||||
const uint256 signature_hash = Hash(unsigned_tx);
|
||||
const uint256 message_hash1 = Hash(prefixed_message);
|
||||
const uint256 message_hash2 = MessageHash(unsigned_tx);
|
||||
|
||||
BOOST_CHECK_EQUAL(message_hash1, message_hash2);
|
||||
|
||||
Reference in New Issue
Block a user