Page MenuHomePhabricator

D1619.id4485.diff
No OneTemporary

D1619.id4485.diff

diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -35,7 +35,7 @@
// Uncomment if you want to output updated JSON tests.
// #define UPDATE_JSON_TESTS
-static const unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
+static const uint32_t flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC;
struct ScriptErrorDesc {
ScriptError_t err;
@@ -258,6 +258,27 @@
havePush = true;
}
+ std::vector<uint8_t> DoSign(const CKey &key, const uint256 &hash,
+ unsigned int lenR = 32,
+ unsigned int lenS = 32) const {
+ std::vector<uint8_t> vchSig, r, s;
+ uint32_t iter = 0;
+ do {
+ key.Sign(hash, vchSig, iter++);
+ if ((lenS == 33) != (vchSig[5 + vchSig[3]] == 33)) {
+ NegateSignatureS(vchSig);
+ }
+
+ r = std::vector<uint8_t>(vchSig.begin() + 4,
+ vchSig.begin() + 4 + vchSig[3]);
+ s = std::vector<uint8_t>(vchSig.begin() + 6 + vchSig[3],
+ vchSig.begin() + 6 + vchSig[3] +
+ vchSig[5 + vchSig[3]]);
+ } while (lenR != r.size() || lenS != s.size());
+
+ return vchSig;
+ }
+
public:
TestBuilder(const CScript &script_, const std::string &comment_, int flags_,
bool P2SH = false, Amount nValue_ = Amount(0))
@@ -309,21 +330,7 @@
uint32_t flags = SCRIPT_ENABLE_SIGHASH_FORKID) {
uint256 hash = SignatureHash(script, CTransaction(spendTx), 0,
sigHashType, amount, nullptr, flags);
- std::vector<uint8_t> vchSig, r, s;
- uint32_t iter = 0;
- do {
- key.Sign(hash, vchSig, iter++);
- if ((lenS == 33) != (vchSig[5 + vchSig[3]] == 33)) {
- NegateSignatureS(vchSig);
- }
-
- r = std::vector<uint8_t>(vchSig.begin() + 4,
- vchSig.begin() + 4 + vchSig[3]);
- s = std::vector<uint8_t>(vchSig.begin() + 6 + vchSig[3],
- vchSig.begin() + 6 + vchSig[3] +
- vchSig[5 + vchSig[3]]);
- } while (lenR != r.size() || lenS != s.size());
-
+ std::vector<uint8_t> vchSig = DoSign(key, hash, lenR, lenS);
vchSig.push_back(static_cast<uint8_t>(sigHashType.getRawSigHashType()));
DoPush(vchSig);
return *this;

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 22, 09:55 (5 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4559193
Default Alt Text
D1619.id4485.diff (2 KB)

Event Timeline