Fix diversifier_index_t less than operator.
This commit is contained in:
parent
0951fe22d8
commit
e4e77eb389
|
@ -159,3 +159,14 @@ TEST(ZIP32, diversifier_index_t_increment)
|
|||
EXPECT_EQ(d_zero, d_one);
|
||||
}
|
||||
|
||||
TEST(ZIP32, diversifier_index_t_lt)
|
||||
{
|
||||
EXPECT_TRUE(libzcash::diversifier_index_t(0) < libzcash::diversifier_index_t(1));
|
||||
EXPECT_FALSE(libzcash::diversifier_index_t(1) < libzcash::diversifier_index_t(0));
|
||||
EXPECT_FALSE(libzcash::diversifier_index_t(0) < libzcash::diversifier_index_t(0));
|
||||
EXPECT_TRUE(libzcash::diversifier_index_t(0xfffffffe) < libzcash::diversifier_index_t(0xffffffff));
|
||||
EXPECT_FALSE(libzcash::diversifier_index_t(0xffffffff) < libzcash::diversifier_index_t(0xfffffffe));
|
||||
EXPECT_TRUE(libzcash::diversifier_index_t(0x01) < libzcash::diversifier_index_t(0xffffffff));
|
||||
EXPECT_FALSE(libzcash::diversifier_index_t(0xffffffff) < libzcash::diversifier_index_t(0x01));
|
||||
}
|
||||
|
||||
|
|
|
@ -334,7 +334,7 @@ std::optional<ZcashdUnifiedAddress> UnifiedFullViewingKey::Address(diversifier_i
|
|||
|
||||
if (transparentKey.has_value()) {
|
||||
// ensure that the diversifier index is small enough for a t-addr
|
||||
if (MAX_TRANSPARENT_CHILD_IDX.less_than_le(j)) return std::nullopt;
|
||||
if (MAX_TRANSPARENT_CHILD_IDX < j) return std::nullopt;
|
||||
|
||||
CExtPubKey changeKey;
|
||||
if (!transparentKey.value().Derive(changeKey, 0)) {
|
||||
|
|
|
@ -195,11 +195,12 @@ public:
|
|||
return false; //overflow
|
||||
}
|
||||
|
||||
// treat as little-endian for numeric comparison
|
||||
bool less_than_le(const diversifier_index_t& other) const {
|
||||
friend bool operator<(const diversifier_index_t& a, const diversifier_index_t& b) {
|
||||
for (int i = 10; i >= 0; i--) {
|
||||
if (data[i] < other.data[i]) {
|
||||
return true;
|
||||
if (a.data[i] == b.data[i]) {
|
||||
continue;
|
||||
} else {
|
||||
return a.data[i] < b.data[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue