Remove default ctors from SecretKey and PublicKey: (#4607)

* It is now an invariant that all constructed Public Keys are valid,
  non-empty and contain 33 bytes of data.
* Additionally, the memory footprint of the PublicKey class is reduced.
  The size_ data member is declared as static.
* Distinguish and identify the PublisherList retrieved from the local
  config file, versus the ones obtained from other validators.
* Fixes #2942
This commit is contained in:
Chenna Keshava B S
2024-03-05 09:02:53 -08:00
committed by GitHub
parent 97863e0b62
commit 62dae3c6c6
39 changed files with 545 additions and 349 deletions

View File

@@ -363,10 +363,12 @@ public:
}
// Try some random secret keys
std::array<PublicKey, 32> keys;
std::vector<PublicKey> keys;
keys.reserve(32);
for (std::size_t i = 0; i != keys.size(); ++i)
keys[i] = derivePublicKey(keyType, randomSecretKey());
for (std::size_t i = 0; i != keys.capacity(); ++i)
keys.emplace_back(derivePublicKey(keyType, randomSecretKey()));
BEAST_EXPECT(keys.size() == 32);
for (std::size_t i = 0; i != keys.size(); ++i)
{
@@ -447,7 +449,11 @@ public:
BEAST_EXPECT(pk1 == pk2);
BEAST_EXPECT(pk2 == pk1);
PublicKey pk3;
PublicKey pk3 = derivePublicKey(
KeyType::secp256k1,
generateSecretKey(
KeyType::secp256k1, generateSeed("arbitraryPassPhrase")));
// Testing the copy assignment operation of PublicKey class
pk3 = pk2;
BEAST_EXPECT(pk3 == pk2);
BEAST_EXPECT(pk1 == pk3);

View File

@@ -17,7 +17,6 @@
*/
//==============================================================================
#include <ripple/basics/Log.h>
#include <ripple/beast/unit_test.h>
#include <ripple/json/json_reader.h>
#include <ripple/json/to_string.h>
@@ -609,12 +608,7 @@ public:
auto const kp =
generateKeyPair(KeyType::secp256k1, generateSeed("masterpassphrase"));
st[sf5] = kp.first;
BEAST_EXPECT(st[sf5] != PublicKey{});
st[~sf5] = std::nullopt;
#if 0
pk = st[sf5];
BEAST_EXPECT(pk.size() == 0);
#endif
}
// By reference fields

View File

@@ -275,10 +275,12 @@ public:
}
// Try some random secret keys
std::array<SecretKey, 32> keys;
std::vector<SecretKey> keys;
keys.reserve(32);
for (std::size_t i = 0; i != keys.size(); ++i)
keys[i] = randomSecretKey();
for (std::size_t i = 0; i != keys.capacity(); ++i)
keys.emplace_back(randomSecretKey());
BEAST_EXPECT(keys.size() == 32);
for (std::size_t i = 0; i != keys.size(); ++i)
{