Skip to content

Commit

Permalink
Bug: invalid G1 and G2 cached in PrivateKey (#289)
Browse files Browse the repository at this point in the history
* QA: test cache invalidation for PrivateKey copy assignment operator

* BugFix: Invalidate caches in PrivateKey copy assignment operator
  • Loading branch information
random-zebra authored Nov 10, 2021
1 parent 6cb0e98 commit fe7112f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/privatekey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ PrivateKey& PrivateKey::operator=(const PrivateKey& other)
{
CheckKeyData();
other.CheckKeyData();
InvalidateCaches();
bn_copy(keydata, other.keydata);
return *this;
}
Expand Down
4 changes: 4 additions & 0 deletions src/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,12 @@ TEST_CASE("class PrivateKey") {
REQUIRE(!pk3.IsZero());
REQUIRE(pk1 != pk2);
REQUIRE(pk3 == pk2);
REQUIRE(pk2.GetG1Element().IsValid()); // cache previous g1
REQUIRE(pk2.GetG2Element().IsValid()); // cache previous g2
pk2 = pk1;
REQUIRE(pk1 == pk2);
REQUIRE(pk1.GetG1Element() == pk2.GetG1Element());
REQUIRE(pk1.GetG2Element() == pk2.GetG2Element());
REQUIRE(pk3 != pk2);
}
SECTION("Move {constructor|assignment operator}") {
Expand Down

0 comments on commit fe7112f

Please sign in to comment.