mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
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:
committed by
GitHub
parent
97863e0b62
commit
62dae3c6c6
@@ -16,8 +16,6 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/json/json_value.h>
|
||||
#include <ripple/json/json_writer.h>
|
||||
#include <ripple/protocol/ErrorCodes.h>
|
||||
@@ -337,8 +335,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -348,8 +349,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -359,8 +363,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
keyType.emplace("secp256k1");
|
||||
@@ -375,8 +382,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -388,8 +398,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -401,8 +414,11 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(ret.first == publicKey);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(ret->first == publicKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,10 +432,10 @@ public:
|
||||
params[jss::secret] = 314159265;
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'secret', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -430,10 +446,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'secret', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -445,7 +461,7 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'secret', not string.");
|
||||
@@ -460,10 +476,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"The secret field is not allowed if key_type is used.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
// Specify unknown or bad "key_type"
|
||||
@@ -475,9 +491,9 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] == "Invalid field 'key_type'.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -488,10 +504,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'key_type', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -502,10 +518,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'key_type', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
// Specify non-string passphrase
|
||||
@@ -517,10 +533,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'passphrase', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a passphrase: object
|
||||
@@ -531,10 +547,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'passphrase', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a passphrase: array
|
||||
@@ -545,10 +561,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'passphrase', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a passphrase: empty string
|
||||
@@ -559,8 +575,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
// Specify non-string or invalid seed
|
||||
@@ -572,10 +588,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a string: object
|
||||
@@ -586,10 +602,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a string: array
|
||||
@@ -600,10 +616,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a seed: empty
|
||||
@@ -614,8 +630,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a seed: invalid characters
|
||||
@@ -626,8 +642,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a seed: random string
|
||||
@@ -638,8 +654,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
// Specify non-string or invalid seed_hex
|
||||
@@ -651,10 +667,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed_hex', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a string: object
|
||||
@@ -665,10 +681,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed_hex', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not a string: array
|
||||
@@ -679,10 +695,10 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(
|
||||
error[jss::error_message] ==
|
||||
"Invalid field 'seed_hex', not string.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // empty
|
||||
@@ -693,8 +709,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // short
|
||||
@@ -705,8 +721,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // not hex
|
||||
@@ -717,8 +733,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
|
||||
{ // overlong
|
||||
@@ -730,8 +746,8 @@ public:
|
||||
|
||||
auto ret = keypairForSignature(params, error);
|
||||
BEAST_EXPECT(contains_error(error));
|
||||
BEAST_EXPECT(!ret);
|
||||
BEAST_EXPECT(error[jss::error_message] == "Disallowed seed.");
|
||||
BEAST_EXPECT(ret.first.size() == 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -750,8 +766,11 @@ public:
|
||||
auto ret = keypairForSignature(params, error);
|
||||
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(toBase58(calcAccountID(ret.first)) == addr);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(toBase58(calcAccountID(ret->first)) == addr);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
@@ -779,8 +798,11 @@ public:
|
||||
auto ret = keypairForSignature(params, error);
|
||||
|
||||
BEAST_EXPECT(!contains_error(error));
|
||||
BEAST_EXPECT(ret.first.size() != 0);
|
||||
BEAST_EXPECT(toBase58(calcAccountID(ret.first)) == addr);
|
||||
if (BEAST_EXPECT(ret))
|
||||
{
|
||||
BEAST_EXPECT(ret->first.size() != 0);
|
||||
BEAST_EXPECT(toBase58(calcAccountID(ret->first)) == addr);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user