Clean up and modernize code:

This commit removes obsolete comments, dead or no longer useful
code, and workarounds for several issues that were present in older
compilers that we no longer support.

Specifically:

- It improves the transaction metadata handling class, simplifying
  its use and making it less error-prone.
- It reduces the footprint of the Serializer class by consolidating
  code and leveraging templates.
- It cleanups the ST* class hierarchy, removing dead code, improving
  and consolidating code to reduce complexity and code duplication.
- It shores up the handling of currency codes and the conversation
  between 160-bit currency codes and their string representation.
- It migrates beast::secure_erase to the ripple namespace and uses
  a call to OpenSSL_cleanse instead of the custom implementation.
This commit is contained in:
Nik Bougalis
2020-03-27 14:26:46 -07:00
parent 6c72d5cf7e
commit dbee3f01b7
45 changed files with 244 additions and 703 deletions

View File

@@ -39,7 +39,7 @@ struct STAccount_test : public beast::unit_test::suite
Serializer s;
defaultAcct.add(s); // Asserts in debug build
BEAST_EXPECT(s.size() == 1);
BEAST_EXPECT(s.getHex() == "00");
BEAST_EXPECT(strHex(s) == "00");
SerialIter sit(s.slice());
STAccount const deserializedDefault(sit, sfAccount);
BEAST_EXPECT(deserializedDefault.isEquivalent(defaultAcct));
@@ -65,7 +65,7 @@ struct STAccount_test : public beast::unit_test::suite
Serializer s;
sfAcct.add(s);
BEAST_EXPECT(s.size() == 1);
BEAST_EXPECT(s.getHex() == "00");
BEAST_EXPECT(strHex(s) == "00");
SerialIter sit(s.slice());
STAccount const deserializedSf(sit, sfAccount);
BEAST_EXPECT(deserializedSf.isEquivalent(sfAcct));
@@ -83,7 +83,7 @@ struct STAccount_test : public beast::unit_test::suite
zeroAcct.add(s);
BEAST_EXPECT(s.size() == 21);
BEAST_EXPECT(
s.getHex() == "140000000000000000000000000000000000000000");
strHex(s) == "140000000000000000000000000000000000000000");
SerialIter sit(s.slice());
STAccount const deserializedZero(sit, sfAccount);
BEAST_EXPECT(deserializedZero.isEquivalent(zeroAcct));

View File

@@ -103,75 +103,6 @@ public:
return Buffer{Slice{b.data(), b.size()}};
}
// VFALCO We can remove this commented out code
// later, when we have confidence in the vectors.
/*
Buffer
makeNonCanonical(Buffer const& sig)
{
secp256k1_ecdsa_signature sigin;
BEAST_EXPECT(secp256k1_ecdsa_signature_parse_der(
secp256k1Context(),
&sigin,
reinterpret_cast<unsigned char const*>(
sig.data()),
sig.size()) == 1);
secp256k1_ecdsa_signature sigout;
BEAST_EXPECT(secp256k1_ecdsa_signature_denormalize(
secp256k1Context(),
&sigout,
&sigin) == 1);
unsigned char buf[72];
size_t len = sizeof(buf);
BEAST_EXPECT(secp256k1_ecdsa_signature_serialize_der(
secp256k1Context(),
buf,
&len,
&sigout) == 1);
return Buffer{buf, len};
}
void
makeCanonicalityTestVectors()
{
uint256 digest;
beast::rngfill (
digest.data(),
digest.size(),
crypto_prng());
log << "digest " << strHex(digest.data(), digest.size()) << std::endl;
auto const sk = randomSecretKey();
auto const pk = derivePublicKey(KeyType::secp256k1, sk);
log << "public " << pk << std::endl;
log << "secret " << sk.to_string() << std::endl;
auto sig = signDigest(pk, sk, digest);
log << "canonical sig " << strHex(sig) << std::endl;
auto const non = makeNonCanonical(sig);
log << "non-canon sig " << strHex(non) << std::endl;
{
auto const canonicality = ecdsaCanonicality(sig);
BEAST_EXPECT(canonicality);
BEAST_EXPECT(*canonicality == ECDSACanonicality::fullyCanonical);
}
{
auto const canonicality = ecdsaCanonicality(non);
BEAST_EXPECT(canonicality);
BEAST_EXPECT(*canonicality != ECDSACanonicality::fullyCanonical);
}
BEAST_EXPECT(verifyDigest(pk, digest, sig, false));
BEAST_EXPECT(verifyDigest(pk, digest, sig, true));
BEAST_EXPECT(verifyDigest(pk, digest, non, false));
BEAST_EXPECT(! verifyDigest(pk, digest, non, true));
}
*/
// Ensure that verification does the right thing with
// respect to the matrix of canonicality variables.
void