mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-18 21:35:13 +01:00
Merge bitcoin/bitcoin#21817: refactor: Replace &foo[0] with foo.data()
fac30eec42
refactor: Replace &foo[0] with foo.data() (MarcoFalke)faece47c47
refactor: Avoid &foo[0] on C-Style arrays (MarcoFalke)face961109
refactor: Use only one temporary buffer in CreateObfuscateKey (MarcoFalke)fa05dddc42
refactor: Use CPubKey vector constructor where possible (MarcoFalke)fabb6dfe6e
script: Replace address-of idiom with vector data() method (Guido Vranken) Pull request description: The main theme of this refactor is to replace `&foo[0]` with `foo.data()`. The first commit is taken from #21781 with the rationale: * In CSignatureCache::ComputeEntryECDSA, change the way a vector pointer is resolved to prevent invoking undefined behavior if the vector is empty. The other commits aim to remove all `&foo[0]`, where `foo` is any kind of byte representation. The rationale: * Sometimes alternative code without any raw data pointers is easier to read (refer to the respective commit message for details) * If the raw data pointer is needed, `foo.data()` should be preferred, as pointed out in the developer notes. This addresses the instances that have been missed in commit592404f03f
, and https://github.com/bitcoin/bitcoin/pull/9804 ACKs for top commit: laanwj: Code review ACKfac30eec42
practicalswift: cr ACKfac30eec42
: patch looks correct promag: Code review ACKfac30eec42
. Tree-SHA512: e7e73146edbc78911a8e8c728b0a1c6b0ed9a88a008e650aa5dbffe72425bd42c76df70199a9cf7e02637448d7593e0eac52fd0f91f59240283e1390ee21bfa5
This commit is contained in:
commit
32f1f021bf
@ -45,7 +45,7 @@ int main()
|
||||
stream << vanillaSpendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
auto op0Result = bitcoinconsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, (const unsigned char*)&stream[0], stream.size(), 0, bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
|
||||
auto op0Result = bitcoinconsensus_verify_script_with_amount(pubKeyScript.data(), pubKeyScript.size(), amount, stream.data(), stream.size(), 0, bitcoinconsensus_SCRIPT_FLAGS_VERIFY_ALL, &err);
|
||||
std::cout << "Op0 result: " << op0Result << ", error code " << err << std::endl;
|
||||
|
||||
getchar();
|
||||
|
@ -124,7 +124,7 @@ bool DecompressScript(CScript& script, unsigned int nSize, const CompressedScrip
|
||||
unsigned char vch[33] = {};
|
||||
vch[0] = nSize - 2;
|
||||
memcpy(&vch[1], in.data(), 32);
|
||||
CPubKey pubkey(&vch[0], &vch[33]);
|
||||
CPubKey pubkey{vch};
|
||||
if (!pubkey.Decompress())
|
||||
return false;
|
||||
assert(pubkey.size() == 65);
|
||||
|
@ -220,10 +220,9 @@ const unsigned int CDBWrapper::OBFUSCATE_KEY_NUM_BYTES = 8;
|
||||
*/
|
||||
std::vector<unsigned char> CDBWrapper::CreateObfuscateKey() const
|
||||
{
|
||||
unsigned char buff[OBFUSCATE_KEY_NUM_BYTES];
|
||||
GetRandBytes(buff, OBFUSCATE_KEY_NUM_BYTES);
|
||||
return std::vector<unsigned char>(&buff[0], &buff[OBFUSCATE_KEY_NUM_BYTES]);
|
||||
|
||||
std::vector<uint8_t> ret(OBFUSCATE_KEY_NUM_BYTES);
|
||||
GetRandBytes(ret.data(), OBFUSCATE_KEY_NUM_BYTES);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool CDBWrapper::IsEmpty()
|
||||
|
@ -293,7 +293,7 @@ bool CKey::Derive(CKey& keyChild, ChainCode &ccChild, unsigned int nChild, const
|
||||
bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
|
||||
out.nDepth = nDepth + 1;
|
||||
CKeyID id = key.GetPubKey().GetID();
|
||||
memcpy(&out.vchFingerprint[0], &id, 4);
|
||||
memcpy(out.vchFingerprint, &id, 4);
|
||||
out.nChild = _nChild;
|
||||
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
|
||||
}
|
||||
@ -312,7 +312,7 @@ void CExtKey::SetSeed(const unsigned char *seed, unsigned int nSeedLen) {
|
||||
CExtPubKey CExtKey::Neuter() const {
|
||||
CExtPubKey ret;
|
||||
ret.nDepth = nDepth;
|
||||
memcpy(&ret.vchFingerprint[0], &vchFingerprint[0], 4);
|
||||
memcpy(ret.vchFingerprint, vchFingerprint, 4);
|
||||
ret.nChild = nChild;
|
||||
ret.pubkey = key.GetPubKey();
|
||||
ret.chaincode = chaincode;
|
||||
|
@ -151,7 +151,7 @@ struct CExtKey {
|
||||
friend bool operator==(const CExtKey& a, const CExtKey& b)
|
||||
{
|
||||
return a.nDepth == b.nDepth &&
|
||||
memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], sizeof(vchFingerprint)) == 0 &&
|
||||
memcmp(a.vchFingerprint, b.vchFingerprint, sizeof(vchFingerprint)) == 0 &&
|
||||
a.nChild == b.nChild &&
|
||||
a.chaincode == b.chaincode &&
|
||||
a.key == b.key;
|
||||
|
@ -293,7 +293,7 @@ void CExtPubKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
|
||||
bool CExtPubKey::Derive(CExtPubKey &out, unsigned int _nChild) const {
|
||||
out.nDepth = nDepth + 1;
|
||||
CKeyID id = pubkey.GetID();
|
||||
memcpy(&out.vchFingerprint[0], &id, 4);
|
||||
memcpy(out.vchFingerprint, &id, 4);
|
||||
out.nChild = _nChild;
|
||||
return pubkey.Derive(out.pubkey, out.chaincode, _nChild, chaincode);
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ public:
|
||||
}
|
||||
|
||||
//! Construct a public key from a byte vector.
|
||||
explicit CPubKey(const std::vector<unsigned char>& _vch)
|
||||
explicit CPubKey(Span<const uint8_t> _vch)
|
||||
{
|
||||
Set(_vch.begin(), _vch.end());
|
||||
}
|
||||
@ -247,7 +247,7 @@ struct CExtPubKey {
|
||||
friend bool operator==(const CExtPubKey &a, const CExtPubKey &b)
|
||||
{
|
||||
return a.nDepth == b.nDepth &&
|
||||
memcmp(&a.vchFingerprint[0], &b.vchFingerprint[0], sizeof(vchFingerprint)) == 0 &&
|
||||
memcmp(a.vchFingerprint, b.vchFingerprint, sizeof(vchFingerprint)) == 0 &&
|
||||
a.nChild == b.nChild &&
|
||||
a.chaincode == b.chaincode &&
|
||||
a.pubkey == b.pubkey;
|
||||
|
@ -248,7 +248,7 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
|
||||
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssTx << *newTx;
|
||||
transaction_array.append((const char*)&(ssTx[0]), ssTx.size());
|
||||
transaction_array.append((const char*)ssTx.data(), ssTx.size());
|
||||
}
|
||||
|
||||
// Add addresses / update labels that we've sent to the address book,
|
||||
|
@ -628,7 +628,7 @@ std::vector<unsigned char> FastRandomContext::randbytes(size_t len)
|
||||
if (requires_seed) RandomSeed();
|
||||
std::vector<unsigned char> ret(len);
|
||||
if (len > 0) {
|
||||
rng.Keystream(&ret[0], len);
|
||||
rng.Keystream(ret.data(), len);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -1098,7 +1098,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
|
||||
TxoutType txntype = Solver(script, data);
|
||||
|
||||
if (txntype == TxoutType::PUBKEY) {
|
||||
CPubKey pubkey(data[0].begin(), data[0].end());
|
||||
CPubKey pubkey(data[0]);
|
||||
if (pubkey.IsValid()) {
|
||||
return std::make_unique<PKDescriptor>(InferPubkey(pubkey, ctx, provider));
|
||||
}
|
||||
@ -1122,7 +1122,7 @@ std::unique_ptr<DescriptorImpl> InferScript(const CScript& script, ParseScriptCo
|
||||
if (txntype == TxoutType::MULTISIG) {
|
||||
std::vector<std::unique_ptr<PubkeyProvider>> providers;
|
||||
for (size_t i = 1; i + 1 < data.size(); ++i) {
|
||||
CPubKey pubkey(data[i].begin(), data[i].end());
|
||||
CPubKey pubkey(data[i]);
|
||||
providers.push_back(InferPubkey(pubkey, ctx, provider));
|
||||
}
|
||||
return std::make_unique<MultisigDescriptor>((int)data[0][0], std::move(providers));
|
||||
|
@ -1890,7 +1890,7 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
|
||||
const valtype& script_bytes = SpanPopBack(stack);
|
||||
exec_script = CScript(script_bytes.begin(), script_bytes.end());
|
||||
uint256 hash_exec_script;
|
||||
CSHA256().Write(&exec_script[0], exec_script.size()).Finalize(hash_exec_script.begin());
|
||||
CSHA256().Write(exec_script.data(), exec_script.size()).Finalize(hash_exec_script.begin());
|
||||
if (memcmp(hash_exec_script.begin(), program.data(), 32)) {
|
||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
|
||||
}
|
||||
|
@ -53,14 +53,14 @@ public:
|
||||
ComputeEntryECDSA(uint256& entry, const uint256 &hash, const std::vector<unsigned char>& vchSig, const CPubKey& pubkey) const
|
||||
{
|
||||
CSHA256 hasher = m_salted_hasher_ecdsa;
|
||||
hasher.Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(&vchSig[0], vchSig.size()).Finalize(entry.begin());
|
||||
hasher.Write(hash.begin(), 32).Write(pubkey.data(), pubkey.size()).Write(vchSig.data(), vchSig.size()).Finalize(entry.begin());
|
||||
}
|
||||
|
||||
void
|
||||
ComputeEntrySchnorr(uint256& entry, const uint256 &hash, Span<const unsigned char> sig, const XOnlyPubKey& pubkey) const
|
||||
{
|
||||
CSHA256 hasher = m_salted_hasher_schnorr;
|
||||
hasher.Write(hash.begin(), 32).Write(&pubkey[0], pubkey.size()).Write(sig.data(), sig.size()).Finalize(entry.begin());
|
||||
hasher.Write(hash.begin(), 32).Write(pubkey.data(), pubkey.size()).Write(sig.data(), sig.size()).Finalize(entry.begin());
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -167,7 +167,7 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
|
||||
return true;
|
||||
|
||||
case TxoutType::WITNESS_V0_SCRIPTHASH:
|
||||
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(h160.begin());
|
||||
CRIPEMD160().Write(vSolutions[0].data(), vSolutions[0].size()).Finalize(h160.begin());
|
||||
if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) {
|
||||
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
|
||||
return true;
|
||||
|
@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_ckey_id)
|
||||
// Check compressed script
|
||||
BOOST_CHECK_EQUAL(out.size(), 21U);
|
||||
BOOST_CHECK_EQUAL(out[0], 0x00);
|
||||
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[3], 20), 0); // compare the 20 relevant chars of the CKeyId in the script
|
||||
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 3, 20), 0); // compare the 20 relevant chars of the CKeyId in the script
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
|
||||
@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_cscript_id)
|
||||
// Check compressed script
|
||||
BOOST_CHECK_EQUAL(out.size(), 21U);
|
||||
BOOST_CHECK_EQUAL(out[0], 0x01);
|
||||
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 20), 0); // compare the 20 relevant chars of the CScriptId in the script
|
||||
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 20), 0); // compare the 20 relevant chars of the CScriptId in the script
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
|
||||
@ -113,8 +113,8 @@ BOOST_AUTO_TEST_CASE(compress_script_to_compressed_pubkey_id)
|
||||
|
||||
// Check compressed script
|
||||
BOOST_CHECK_EQUAL(out.size(), 33U);
|
||||
BOOST_CHECK_EQUAL(memcmp(&out[0], &script[1], 1), 0);
|
||||
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // compare the 32 chars of the compressed CPubKey
|
||||
BOOST_CHECK_EQUAL(memcmp(out.data(), script.data() + 1, 1), 0);
|
||||
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // compare the 32 chars of the compressed CPubKey
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
|
||||
@ -130,7 +130,7 @@ BOOST_AUTO_TEST_CASE(compress_script_to_uncompressed_pubkey_id)
|
||||
|
||||
// Check compressed script
|
||||
BOOST_CHECK_EQUAL(out.size(), 33U);
|
||||
BOOST_CHECK_EQUAL(memcmp(&out[1], &script[2], 32), 0); // first 32 chars of CPubKey are copied into out[1:]
|
||||
BOOST_CHECK_EQUAL(memcmp(out.data() + 1, script.data() + 2, 32), 0); // first 32 chars of CPubKey are copied into out[1:]
|
||||
BOOST_CHECK_EQUAL(out[0], 0x04 | (script[65] & 0x01)); // least significant bit (lsb) of last char of pubkey is mapped into out[0]
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ static void TestVector(const Hasher &h, const In &in, const Out &out) {
|
||||
hash.resize(out.size());
|
||||
{
|
||||
// Test that writing the whole input string at once works.
|
||||
Hasher(h).Write((unsigned char*)&in[0], in.size()).Finalize(&hash[0]);
|
||||
Hasher(h).Write((const uint8_t*)in.data(), in.size()).Finalize(hash.data());
|
||||
BOOST_CHECK(hash == out);
|
||||
}
|
||||
for (int i=0; i<32; i++) {
|
||||
@ -42,15 +42,15 @@ static void TestVector(const Hasher &h, const In &in, const Out &out) {
|
||||
size_t pos = 0;
|
||||
while (pos < in.size()) {
|
||||
size_t len = InsecureRandRange((in.size() - pos + 1) / 2 + 1);
|
||||
hasher.Write((unsigned char*)&in[pos], len);
|
||||
hasher.Write((const uint8_t*)in.data() + pos, len);
|
||||
pos += len;
|
||||
if (pos > 0 && pos + 2 * out.size() > in.size() && pos < in.size()) {
|
||||
// Test that writing the rest at once to a copy of a hasher works.
|
||||
Hasher(hasher).Write((unsigned char*)&in[pos], in.size() - pos).Finalize(&hash[0]);
|
||||
Hasher(hasher).Write((const uint8_t*)in.data() + pos, in.size() - pos).Finalize(hash.data());
|
||||
BOOST_CHECK(hash == out);
|
||||
}
|
||||
}
|
||||
hasher.Finalize(&hash[0]);
|
||||
hasher.Finalize(hash.data());
|
||||
BOOST_CHECK(hash == out);
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +273,7 @@ CScript ConsumeScript(FuzzedDataProvider& fuzzed_data_provider, const size_t max
|
||||
CScript r_script{b.begin(), b.end()};
|
||||
if (maybe_p2wsh && fuzzed_data_provider.ConsumeBool()) {
|
||||
uint256 script_hash;
|
||||
CSHA256().Write(&r_script[0], r_script.size()).Finalize(script_hash.begin());
|
||||
CSHA256().Write(r_script.data(), r_script.size()).Finalize(script_hash.begin());
|
||||
r_script.clear();
|
||||
r_script << OP_0 << ToByteVector(script_hash);
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(script_standard_Solver_success)
|
||||
|
||||
// TxoutType::WITNESS_V0_SCRIPTHASH
|
||||
uint256 scriptHash;
|
||||
CSHA256().Write(&redeemScript[0], redeemScript.size())
|
||||
CSHA256().Write(redeemScript.data(), redeemScript.size())
|
||||
.Finalize(scriptHash.begin());
|
||||
|
||||
s.clear();
|
||||
@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
|
||||
witnessScript << OP_1 << ToByteVector(pubkeys[0]) << OP_1 << OP_CHECKMULTISIG;
|
||||
|
||||
uint256 scriptHash;
|
||||
CSHA256().Write(&witnessScript[0], witnessScript.size())
|
||||
CSHA256().Write(witnessScript.data(), witnessScript.size())
|
||||
.Finalize(scriptHash.begin());
|
||||
|
||||
expected.clear();
|
||||
|
@ -155,10 +155,10 @@ void DoTest(const CScript& scriptPubKey, const CScript& scriptSig, const CScript
|
||||
if (libconsensus_flags == flags) {
|
||||
int expectedSuccessCode = expect ? 1 : 0;
|
||||
if (flags & bitcoinconsensus_SCRIPT_FLAGS_VERIFY_WITNESS) {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), txCredit.vout[0].nValue, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), txCredit.vout[0].nValue, stream.data(), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
} else {
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), 0, (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script_with_amount(scriptPubKey.data(), scriptPubKey.size(), 0, stream.data(), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
BOOST_CHECK_MESSAGE(bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), 0, libconsensus_flags, nullptr) == expectedSuccessCode, message);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -224,7 +224,7 @@ struct KeyData
|
||||
pubkey0 = key0.GetPubKey();
|
||||
pubkey0H = key0.GetPubKey();
|
||||
pubkey0C = key0C.GetPubKey();
|
||||
*const_cast<unsigned char*>(&pubkey0H[0]) = 0x06 | (pubkey0H[64] & 1);
|
||||
*const_cast<unsigned char*>(pubkey0H.data()) = 0x06 | (pubkey0H[64] & 1);
|
||||
|
||||
key1.Set(vchKey1, vchKey1 + 32, false);
|
||||
key1C.Set(vchKey1, vchKey1 + 32, true);
|
||||
@ -290,7 +290,7 @@ public:
|
||||
} else if (wm == WitnessMode::SH) {
|
||||
witscript = scriptPubKey;
|
||||
uint256 hash;
|
||||
CSHA256().Write(&witscript[0], witscript.size()).Finalize(hash.begin());
|
||||
CSHA256().Write(witscript.data(), witscript.size()).Finalize(hash.begin());
|
||||
scriptPubKey = CScript() << witnessversion << ToByteVector(hash);
|
||||
}
|
||||
if (P2SH) {
|
||||
@ -774,7 +774,7 @@ BOOST_AUTO_TEST_CASE(script_build)
|
||||
{
|
||||
CScript witscript = CScript() << ToByteVector(keys.pubkey0);
|
||||
uint256 hash;
|
||||
CSHA256().Write(&witscript[0], witscript.size()).Finalize(hash.begin());
|
||||
CSHA256().Write(witscript.data(), witscript.size()).Finalize(hash.begin());
|
||||
std::vector<unsigned char> hashBytes = ToByteVector(hash);
|
||||
hashBytes.pop_back();
|
||||
tests.push_back(TestBuilder(CScript() << OP_0 << hashBytes,
|
||||
@ -1520,7 +1520,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_returns_true)
|
||||
stream << spendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 1);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_OK);
|
||||
}
|
||||
@ -1543,7 +1543,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_index_err)
|
||||
stream << spendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_INDEX);
|
||||
}
|
||||
@ -1566,7 +1566,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_size)
|
||||
stream << spendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size() * 2, nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size() * 2, nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_SIZE_MISMATCH);
|
||||
}
|
||||
@ -1589,7 +1589,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_tx_serialization)
|
||||
stream << 0xffffffff;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_TX_DESERIALIZE);
|
||||
}
|
||||
@ -1612,7 +1612,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_amount_required_err)
|
||||
stream << spendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_AMOUNT_REQUIRED);
|
||||
}
|
||||
@ -1635,7 +1635,7 @@ BOOST_AUTO_TEST_CASE(bitcoinconsensus_verify_script_invalid_flags)
|
||||
stream << spendTx;
|
||||
|
||||
bitcoinconsensus_error err;
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), (const unsigned char*)&stream[0], stream.size(), nIn, libconsensus_flags, &err);
|
||||
int result = bitcoinconsensus_verify_script(scriptPubKey.data(), scriptPubKey.size(), stream.data(), stream.size(), nIn, libconsensus_flags, &err);
|
||||
BOOST_CHECK_EQUAL(result, 0);
|
||||
BOOST_CHECK_EQUAL(err, bitcoinconsensus_ERR_INVALID_FLAGS);
|
||||
}
|
||||
@ -1733,7 +1733,7 @@ BOOST_AUTO_TEST_CASE(script_assets_test)
|
||||
size_t length = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
std::string data(length, '\0');
|
||||
file.read(&data[0], data.size());
|
||||
file.read(data.data(), data.size());
|
||||
UniValue tests = read_json(data);
|
||||
BOOST_CHECK(tests.isArray());
|
||||
BOOST_CHECK(tests.size() > 0);
|
||||
|
@ -78,7 +78,7 @@ bool CCrypter::Encrypt(const CKeyingMaterial& vchPlaintext, std::vector<unsigned
|
||||
vchCiphertext.resize(vchPlaintext.size() + AES_BLOCKSIZE);
|
||||
|
||||
AES256CBCEncrypt enc(vchKey.data(), vchIV.data(), true);
|
||||
size_t nLen = enc.Encrypt(&vchPlaintext[0], vchPlaintext.size(), vchCiphertext.data());
|
||||
size_t nLen = enc.Encrypt(vchPlaintext.data(), vchPlaintext.size(), vchCiphertext.data());
|
||||
if(nLen < vchPlaintext.size())
|
||||
return false;
|
||||
vchCiphertext.resize(nLen);
|
||||
@ -97,7 +97,7 @@ bool CCrypter::Decrypt(const std::vector<unsigned char>& vchCiphertext, CKeyingM
|
||||
vchPlaintext.resize(nLen);
|
||||
|
||||
AES256CBCDecrypt dec(vchKey.data(), vchIV.data(), true);
|
||||
nLen = dec.Decrypt(vchCiphertext.data(), vchCiphertext.size(), &vchPlaintext[0]);
|
||||
nLen = dec.Decrypt(vchCiphertext.data(), vchCiphertext.size(), vchPlaintext.data());
|
||||
if(nLen == 0)
|
||||
return false;
|
||||
vchPlaintext.resize(nLen);
|
||||
@ -121,7 +121,7 @@ bool DecryptSecret(const CKeyingMaterial& vMasterKey, const std::vector<unsigned
|
||||
memcpy(chIV.data(), &nIV, WALLET_CRYPTO_IV_SIZE);
|
||||
if(!cKeyCrypter.SetKey(vMasterKey, chIV))
|
||||
return false;
|
||||
return cKeyCrypter.Decrypt(vchCiphertext, *((CKeyingMaterial*)&vchPlaintext));
|
||||
return cKeyCrypter.Decrypt(vchCiphertext, vchPlaintext);
|
||||
}
|
||||
|
||||
bool DecryptKey(const CKeyingMaterial& vMasterKey, const std::vector<unsigned char>& vchCryptedSecret, const CPubKey& vchPubKey, CKey& key)
|
||||
|
@ -469,7 +469,7 @@ RPCHelpMan importpubkey()
|
||||
if (!IsHex(request.params[0].get_str()))
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey must be a hex string");
|
||||
std::vector<unsigned char> data(ParseHex(request.params[0].get_str()));
|
||||
CPubKey pubKey(data.begin(), data.end());
|
||||
CPubKey pubKey(data);
|
||||
if (!pubKey.IsFullyValid())
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey is not a valid public key");
|
||||
|
||||
@ -871,7 +871,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
|
||||
|
||||
switch (script_type) {
|
||||
case TxoutType::PUBKEY: {
|
||||
CPubKey pubkey(solverdata[0].begin(), solverdata[0].end());
|
||||
CPubKey pubkey(solverdata[0]);
|
||||
import_data.used_keys.emplace(pubkey.GetID(), false);
|
||||
return "";
|
||||
}
|
||||
@ -893,7 +893,7 @@ static std::string RecurseImportData(const CScript& script, ImportData& import_d
|
||||
}
|
||||
case TxoutType::MULTISIG: {
|
||||
for (size_t i = 1; i + 1< solverdata.size(); ++i) {
|
||||
CPubKey pubkey(solverdata[i].begin(), solverdata[i].end());
|
||||
CPubKey pubkey(solverdata[i]);
|
||||
import_data.used_keys.emplace(pubkey.GetID(), false);
|
||||
}
|
||||
return "";
|
||||
@ -997,7 +997,7 @@ static UniValue ProcessImportLegacy(ImportData& import_data, std::map<CKeyID, CP
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" must be a hex string");
|
||||
}
|
||||
auto parsed_pubkey = ParseHex(str);
|
||||
CPubKey pubkey(parsed_pubkey.begin(), parsed_pubkey.end());
|
||||
CPubKey pubkey(parsed_pubkey);
|
||||
if (!pubkey.IsFullyValid()) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Pubkey \"" + str + "\" is not a valid public key");
|
||||
}
|
||||
|
@ -154,8 +154,8 @@ bool RecoverDatabaseFile(const fs::path& file_path, bilingual_str& error, std::v
|
||||
warnings.push_back(strprintf(Untranslated("WARNING: WalletBatch::Recover skipping %s: %s"), strType, strErr));
|
||||
continue;
|
||||
}
|
||||
Dbt datKey(&row.first[0], row.first.size());
|
||||
Dbt datValue(&row.second[0], row.second.size());
|
||||
Dbt datKey(row.first.data(), row.first.size());
|
||||
Dbt datValue(row.second.data(), row.second.size());
|
||||
int ret2 = pdbCopy->put(ptxn, &datKey, &datValue, DB_NOOVERWRITE);
|
||||
if (ret2 > 0)
|
||||
fSuccess = false;
|
||||
|
@ -162,7 +162,7 @@ IsMineResult IsMineInner(const LegacyScriptPubKeyMan& keystore, const CScript& s
|
||||
break;
|
||||
}
|
||||
uint160 hash;
|
||||
CRIPEMD160().Write(&vSolutions[0][0], vSolutions[0].size()).Finalize(hash.begin());
|
||||
CRIPEMD160().Write(vSolutions[0].data(), vSolutions[0].size()).Finalize(hash.begin());
|
||||
CScriptID scriptID = CScriptID(hash);
|
||||
CScript subscript;
|
||||
if (keystore.GetCScript(scriptID, subscript)) {
|
||||
|
@ -603,12 +603,12 @@ bool CWallet::EncryptWallet(const SecureString& strWalletPassphrase)
|
||||
CKeyingMaterial _vMasterKey;
|
||||
|
||||
_vMasterKey.resize(WALLET_CRYPTO_KEY_SIZE);
|
||||
GetStrongRandBytes(&_vMasterKey[0], WALLET_CRYPTO_KEY_SIZE);
|
||||
GetStrongRandBytes(_vMasterKey.data(), WALLET_CRYPTO_KEY_SIZE);
|
||||
|
||||
CMasterKey kMasterKey;
|
||||
|
||||
kMasterKey.vchSalt.resize(WALLET_CRYPTO_SALT_SIZE);
|
||||
GetStrongRandBytes(&kMasterKey.vchSalt[0], WALLET_CRYPTO_SALT_SIZE);
|
||||
GetStrongRandBytes(kMasterKey.vchSalt.data(), WALLET_CRYPTO_SALT_SIZE);
|
||||
|
||||
CCrypter crypter;
|
||||
int64_t nStartTime = GetTimeMillis();
|
||||
|
@ -168,7 +168,7 @@ bool CZMQAbstractPublishNotifier::SendZmqMessage(const char *command, const void
|
||||
|
||||
/* send three parts, command & data & a LE 4byte sequence number */
|
||||
unsigned char msgseq[sizeof(uint32_t)];
|
||||
WriteLE32(&msgseq[0], nSequence);
|
||||
WriteLE32(msgseq, nSequence);
|
||||
int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), nullptr);
|
||||
if (rc == -1)
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user