Skip to content
This repository was archived by the owner on Jul 2, 2025. It is now read-only.

Commit fe7112f

Browse files
authored
Bug: invalid G1 and G2 cached in PrivateKey (#289)
* QA: test cache invalidation for PrivateKey copy assignment operator * BugFix: Invalidate caches in PrivateKey copy assignment operator
1 parent 6cb0e98 commit fe7112f

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/privatekey.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ PrivateKey& PrivateKey::operator=(const PrivateKey& other)
8787
{
8888
CheckKeyData();
8989
other.CheckKeyData();
90+
InvalidateCaches();
9091
bn_copy(keydata, other.keydata);
9192
return *this;
9293
}

src/test.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ TEST_CASE("class PrivateKey") {
6565
REQUIRE(!pk3.IsZero());
6666
REQUIRE(pk1 != pk2);
6767
REQUIRE(pk3 == pk2);
68+
REQUIRE(pk2.GetG1Element().IsValid()); // cache previous g1
69+
REQUIRE(pk2.GetG2Element().IsValid()); // cache previous g2
6870
pk2 = pk1;
6971
REQUIRE(pk1 == pk2);
72+
REQUIRE(pk1.GetG1Element() == pk2.GetG1Element());
73+
REQUIRE(pk1.GetG2Element() == pk2.GetG2Element());
7074
REQUIRE(pk3 != pk2);
7175
}
7276
SECTION("Move {constructor|assignment operator}") {

0 commit comments

Comments
 (0)