Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.60.0-b4 #2004

Closed
wants to merge 14 commits into from

Add SecretKey comparison operator (RIPD-1382)

  • Loading branch information...
wilsonianb authored and vinniefalco committed Jan 5, 2017
commit a00e684bf2a088bb432b9f7c4c859ee98c730817
@@ -68,6 +68,24 @@ class SecretKey
to_string() const;
};

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);
}

//------------------------------------------------------------------------------

/** Produces a sequence of secp256k1 key pairs. */
@@ -34,14 +34,6 @@ namespace ripple {

class SecretKey_test : public beast::unit_test::suite
{
static
bool equal(SecretKey const& lhs, SecretKey const& rhs)
{
return std::equal (
lhs.data(), lhs.data() + lhs.size(),
rhs.data(), rhs.data() + rhs.size());
}

public:
using blob = std::vector<std::uint8_t>;

@@ -332,7 +324,7 @@ class SecretKey_test : public beast::unit_test::suite
"pnen77YEeUd4fFKG7iycBWcwKpTaeFRkW2WFostaATy1DSupwXe");
BEAST_EXPECT(sk2);

BEAST_EXPECT(equal (sk1, *sk2));
BEAST_EXPECT(sk1 == *sk2);
}

{
@@ -345,7 +337,7 @@ class SecretKey_test : public beast::unit_test::suite
"paKv46LztLqK3GaKz1rG2nQGN6M4JLyRtxFBYFTw4wAVHtGys36");
BEAST_EXPECT(sk2);

BEAST_EXPECT(equal (sk1, *sk2));
BEAST_EXPECT(sk1 == *sk2);
}

// Try converting short, long and malformed data
@@ -416,11 +408,11 @@ class SecretKey_test : public beast::unit_test::suite

auto const ski = parseBase58<SecretKey> (
TOKEN_NODE_PRIVATE, si);
BEAST_EXPECT(ski && equal(keys[i], *ski));
BEAST_EXPECT(ski && keys[i] == *ski);

for (std::size_t j = i; j != keys.size(); ++j)
{
BEAST_EXPECT(equal (keys[i], keys[j]) == (i == j));
BEAST_EXPECT((keys[i] == keys[j]) == (i == j));

auto const sj = toBase58 (
TokenType::TOKEN_NODE_PRIVATE,
@@ -430,9 +422,9 @@ class SecretKey_test : public beast::unit_test::suite

auto const skj = parseBase58<SecretKey> (
TOKEN_NODE_PRIVATE, sj);
BEAST_EXPECT(skj && equal(keys[j], *skj));
BEAST_EXPECT(skj && keys[j] == *skj);

BEAST_EXPECT(equal (*ski, *skj) == (i == j));
BEAST_EXPECT((*ski == *skj) == (i == j));
}
}
}
@@ -446,11 +438,12 @@ class SecretKey_test : public beast::unit_test::suite
generateSeed ("masterpassphrase"));

SecretKey sk2 (sk1);
BEAST_EXPECT(equal (sk1, sk2));
BEAST_EXPECT(sk1 == sk2);

SecretKey sk3;
BEAST_EXPECT(sk3 != sk2);
sk3 = sk2;
BEAST_EXPECT(equal (sk3, sk2));
BEAST_EXPECT(sk3 == sk2);
}

void run() override
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.