Compare commits

..

4 Commits

Author SHA1 Message Date
Pratik Mankawde
826f51d27a Merge branch 'develop' into pratik/Move-key-equals-functions-to-test-files 2026-03-09 19:06:39 +00:00
Pratik Mankawde
33b3e187c5 code reivew changes
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
2026-03-09 16:11:35 +00:00
Pratik Mankawde
91e8d6e158 ordering changes
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
2026-03-09 14:12:52 +00:00
Pratik Mankawde
4329705718 delete compare op from header and added in test module
Signed-off-by: Pratik Mankawde <3397372+pratikmankawde@users.noreply.github.com>
2026-03-09 12:58:22 +00:00
7 changed files with 47 additions and 26 deletions

View File

@@ -134,6 +134,7 @@ test.peerfinder > xrpld.core
test.peerfinder > xrpld.peerfinder
test.peerfinder > xrpl.protocol
test.protocol > test.toplevel
test.protocol > test.unit_test
test.protocol > xrpl.basics
test.protocol > xrpl.json
test.protocol > xrpl.protocol
@@ -171,6 +172,7 @@ test.shamap > xrpl.shamap
test.toplevel > test.csf
test.toplevel > xrpl.json
test.unit_test > xrpl.basics
test.unit_test > xrpl.protocol
tests.libxrpl > xrpl.basics
tests.libxrpl > xrpl.json
tests.libxrpl > xrpl.net

View File

@@ -11,7 +11,7 @@ on:
jobs:
# Call the workflow in the XRPLF/actions repo that runs the pre-commit hooks.
run-hooks:
uses: XRPLF/actions/.github/workflows/pre-commit.yml@44856eb0d6ecb7d376370244324ab3dc8b863bad
uses: XRPLF/actions/.github/workflows/pre-commit.yml@56de1bdf19639e009639a50b8d17c28ca954f267
with:
runs_on: ubuntu-latest
container: '{ "image": "ghcr.io/xrplf/ci/tools-rippled-pre-commit:sha-41ec7c1" }'

View File

@@ -16,8 +16,11 @@ namespace xrpl {
/** A secret key. */
class SecretKey
{
public:
static constexpr std::size_t size_ = 32;
private:
std::uint8_t buf_[32];
std::uint8_t buf_[size_];
public:
using const_iterator = std::uint8_t const*;
@@ -27,9 +30,14 @@ public:
SecretKey&
operator=(SecretKey const&) = default;
bool
operator==(SecretKey const&) = delete;
bool
operator!=(SecretKey const&) = delete;
~SecretKey();
SecretKey(std::array<std::uint8_t, 32> const& data);
SecretKey(std::array<std::uint8_t, size_> const& data);
SecretKey(Slice const& slice);
std::uint8_t const*
@@ -77,18 +85,6 @@ public:
}
};
inline bool
operator==(SecretKey const& lhs, SecretKey const& rhs)
{
return lhs.size() == rhs.size() && std::memcmp(lhs.data(), rhs.data(), rhs.size()) == 0;
}
inline bool
operator!=(SecretKey const& lhs, SecretKey const& rhs)
{
return !(lhs == rhs);
}
//------------------------------------------------------------------------------
/** Parse a secret key */

View File

@@ -1,4 +1,5 @@
#include <test/jtx.h>
#include <test/unit_test/utils.h>
#include <xrpld/app/misc/ValidatorList.h>
@@ -446,7 +447,7 @@ public:
auto const token = loadValidatorToken(tokenBlob);
BEAST_EXPECT(token);
BEAST_EXPECT(token->validationSecret == *valSecret);
BEAST_EXPECT(test::equal(token->validationSecret, *valSecret));
BEAST_EXPECT(token->manifest == manifest);
}
{

View File

@@ -1,4 +1,5 @@
#include <test/jtx/Env.h>
#include <test/unit_test/utils.h>
#include <xrpld/app/misc/ValidatorKeys.h>
#include <xrpld/core/Config.h>
@@ -92,7 +93,7 @@ public:
if (BEAST_EXPECT(k.keys))
{
BEAST_EXPECT(k.keys->publicKey == seedPublicKey);
BEAST_EXPECT(k.keys->secretKey == seedSecretKey);
BEAST_EXPECT(test::equal(k.keys->secretKey, seedSecretKey));
}
BEAST_EXPECT(k.nodeID == seedNodeID);
BEAST_EXPECT(k.manifest.empty());
@@ -119,7 +120,7 @@ public:
if (BEAST_EXPECT(k.keys))
{
BEAST_EXPECT(k.keys->publicKey == tokenPublicKey);
BEAST_EXPECT(k.keys->secretKey == tokenSecretKey);
BEAST_EXPECT(test::equal(k.keys->secretKey, tokenSecretKey));
}
BEAST_EXPECT(k.nodeID == tokenNodeID);
BEAST_EXPECT(k.manifest == tokenManifest);

View File

@@ -1,3 +1,5 @@
#include <test/unit_test/utils.h>
#include <xrpl/beast/unit_test.h>
#include <xrpl/beast/utility/rngfill.h>
#include <xrpl/crypto/csprng.h>
@@ -183,7 +185,7 @@ public:
TokenType::NodePrivate, "pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
BEAST_EXPECT(sk2);
BEAST_EXPECT(sk1 == *sk2);
BEAST_EXPECT(test::equal(sk1, *sk2));
}
{
@@ -193,7 +195,7 @@ public:
TokenType::NodePrivate, "paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
BEAST_EXPECT(sk2);
BEAST_EXPECT(sk1 == *sk2);
BEAST_EXPECT(test::equal(sk1, *sk2));
}
// Try converting short, long and malformed data
@@ -261,20 +263,20 @@ public:
BEAST_EXPECT(!si.empty());
auto const ski = parseBase58<SecretKey>(TokenType::NodePrivate, si);
BEAST_EXPECT(ski && keys[i] == *ski);
BEAST_EXPECT(ski && test::equal(keys[i], *ski));
for (std::size_t j = i; j != keys.size(); ++j)
{
BEAST_EXPECT((keys[i] == keys[j]) == (i == j));
BEAST_EXPECT(test::equal(keys[i], keys[j]) == (i == j));
auto const sj = toBase58(TokenType::NodePrivate, keys[j]);
BEAST_EXPECT((si == sj) == (i == j));
auto const skj = parseBase58<SecretKey>(TokenType::NodePrivate, sj);
BEAST_EXPECT(skj && keys[j] == *skj);
BEAST_EXPECT(skj && test::equal(keys[j], *skj));
BEAST_EXPECT((*ski == *skj) == (i == j));
BEAST_EXPECT(test::equal(*ski, *skj) == (i == j));
}
}
}
@@ -292,7 +294,7 @@ public:
auto kp = generateKeyPair(KeyType::secp256k1, Seed{makeSlice(test.seed)});
BEAST_EXPECT(kp.first == PublicKey{makeSlice(test.pubkey)});
BEAST_EXPECT(kp.second == SecretKey{makeSlice(test.seckey)});
BEAST_EXPECT(test::equal(kp.second, SecretKey{makeSlice(test.seckey)}));
BEAST_EXPECT(calcAccountID(kp.first) == *id);
}
}
@@ -310,7 +312,7 @@ public:
auto kp = generateKeyPair(KeyType::ed25519, Seed{makeSlice(test.seed)});
BEAST_EXPECT(kp.first == PublicKey{makeSlice(test.pubkey)});
BEAST_EXPECT(kp.second == SecretKey{makeSlice(test.seckey)});
BEAST_EXPECT(test::equal(kp.second, SecretKey{makeSlice(test.seckey)}));
BEAST_EXPECT(calcAccountID(kp.first) == *id);
}
}

View File

@@ -0,0 +1,19 @@
#include <xrpl/protocol/SecretKey.h>
#include <cstring>
namespace xrpl {
namespace test {
/// Compare two SecretKey objects for equality.
/// SecretKey::operator== is deleted, so a named function is used
/// to avoid member-function lookup shadowing free-function overloads.
inline bool
equal(SecretKey const& lhs, SecretKey const& rhs)
{
return lhs.size() == SecretKey::size_ && rhs.size() == SecretKey::size_ &&
std::memcmp(lhs.data(), rhs.data(), rhs.size()) == 0;
}
} // namespace test
} // namespace xrpl