Skip to content

Commit facd1fb

Browse files
author
MarcoFalke
committed
refactor: Use Span of std::byte in CExtKey::SetSeed
1 parent fae1006 commit facd1fb

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/key.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,11 @@ bool CExtKey::Derive(CExtKey &out, unsigned int _nChild) const {
340340
return key.Derive(out.key, out.chaincode, _nChild, chaincode);
341341
}
342342

343-
void CExtKey::SetSeed(Span<const uint8_t> seed)
343+
void CExtKey::SetSeed(Span<const std::byte> seed)
344344
{
345345
static const unsigned char hashkey[] = {'B','i','t','c','o','i','n',' ','s','e','e','d'};
346346
std::vector<unsigned char, secure_allocator<unsigned char>> vout(64);
347-
CHMAC_SHA512{hashkey, sizeof(hashkey)}.Write(seed.data(), seed.size()).Finalize(vout.data());
347+
CHMAC_SHA512{hashkey, sizeof(hashkey)}.Write(UCharCast(seed.data()), seed.size()).Finalize(vout.data());
348348
key.Set(vout.data(), vout.data() + 32, true);
349349
memcpy(chaincode.begin(), vout.data() + 32, 32);
350350
nDepth = 0;

src/key.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CKey
8585

8686
//! Simple read-only vector-like interface.
8787
unsigned int size() const { return (fValid ? keydata.size() : 0); }
88-
const unsigned char* data() const { return keydata.data(); }
88+
const std::byte* data() const { return reinterpret_cast<const std::byte*>(keydata.data()); }
8989
const unsigned char* begin() const { return keydata.data(); }
9090
const unsigned char* end() const { return keydata.data() + size(); }
9191

@@ -178,7 +178,7 @@ struct CExtKey {
178178
void Decode(const unsigned char code[BIP32_EXTKEY_SIZE]);
179179
bool Derive(CExtKey& out, unsigned int nChild) const;
180180
CExtPubKey Neuter() const;
181-
void SetSeed(Span<const uint8_t> seed);
181+
void SetSeed(Span<const std::byte> seed);
182182
};
183183

184184
/** Initialize the elliptic curve support. May not be called twice without calling ECC_Stop first. */

src/test/bip32_tests.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,9 @@ const std::vector<std::string> TEST5 = {
120120
"xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHL"
121121
};
122122

123-
void RunTest(const TestVector &test) {
124-
std::vector<unsigned char> seed = ParseHex(test.strHexMaster);
123+
void RunTest(const TestVector& test)
124+
{
125+
std::vector<std::byte> seed{ParseHex<std::byte>(test.strHexMaster)};
125126
CExtKey key;
126127
CExtPubKey pubkey;
127128
key.SetSeed(seed);

src/test/key_io_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ BOOST_AUTO_TEST_CASE(key_io_valid_parse)
3535
continue;
3636
}
3737
std::string exp_base58string = test[0].get_str();
38-
std::vector<unsigned char> exp_payload = ParseHex(test[1].get_str());
38+
const std::vector<std::byte> exp_payload{ParseHex<std::byte>(test[1].get_str())};
3939
const UniValue &metadata = test[2].get_obj();
4040
bool isPrivkey = find_value(metadata, "isPrivkey").get_bool();
4141
SelectParams(find_value(metadata, "chain").get_str());

0 commit comments

Comments
 (0)