mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
refactor: use {Read,Write}BE32 helpers for BIP32 nChild (de)serialization
This commit is contained in:
@@ -343,8 +343,7 @@ CExtPubKey CExtKey::Neuter() const {
|
||||
void CExtKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
|
||||
code[0] = nDepth;
|
||||
memcpy(code+1, vchFingerprint, 4);
|
||||
code[5] = (nChild >> 24) & 0xFF; code[6] = (nChild >> 16) & 0xFF;
|
||||
code[7] = (nChild >> 8) & 0xFF; code[8] = (nChild >> 0) & 0xFF;
|
||||
WriteBE32(code+5, nChild);
|
||||
memcpy(code+9, chaincode.begin(), 32);
|
||||
code[41] = 0;
|
||||
assert(key.size() == 32);
|
||||
@@ -354,7 +353,7 @@ void CExtKey::Encode(unsigned char code[BIP32_EXTKEY_SIZE]) const {
|
||||
void CExtKey::Decode(const unsigned char code[BIP32_EXTKEY_SIZE]) {
|
||||
nDepth = code[0];
|
||||
memcpy(vchFingerprint, code+1, 4);
|
||||
nChild = (code[5] << 24) | (code[6] << 16) | (code[7] << 8) | code[8];
|
||||
nChild = ReadBE32(code+5);
|
||||
memcpy(chaincode.begin(), code+9, 32);
|
||||
key.Set(code+42, code+BIP32_EXTKEY_SIZE, true);
|
||||
if ((nDepth == 0 && (nChild != 0 || ReadLE32(vchFingerprint) != 0)) || code[41] != 0) key = CKey();
|
||||
|
||||
Reference in New Issue
Block a user