mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-03 16:56:36 +00:00
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:
@@ -25,17 +25,6 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
int
|
||||
Serializer::addZeros(size_t uBytes)
|
||||
{
|
||||
int ret = mData.size();
|
||||
|
||||
while (uBytes--)
|
||||
mData.push_back(0);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::add16(std::uint16_t i)
|
||||
{
|
||||
@@ -107,22 +96,6 @@ Serializer::addInteger(std::uint64_t i)
|
||||
return add64(i);
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::add128(const uint128& i)
|
||||
{
|
||||
int ret = mData.size();
|
||||
mData.insert(mData.end(), i.begin(), i.end());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::add256(uint256 const& i)
|
||||
{
|
||||
int ret = mData.size();
|
||||
mData.insert(mData.end(), i.begin(), i.end());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::addRaw(Blob const& vector)
|
||||
{
|
||||
@@ -147,16 +120,6 @@ Serializer::addRaw(const void* ptr, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
Serializer::get256(uint256& o, int offset) const
|
||||
{
|
||||
if ((offset + (256 / 8)) > mData.size())
|
||||
return false;
|
||||
|
||||
memcpy(o.begin(), &(mData.front()) + offset, (256 / 8));
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::addFieldID(int type, int name)
|
||||
{
|
||||
@@ -219,28 +182,6 @@ Serializer::chop(int bytes)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
Serializer::getRaw(Blob& o, int offset, int length) const
|
||||
{
|
||||
if ((offset + length) > mData.size())
|
||||
return false;
|
||||
|
||||
o.assign(mData.begin() + offset, mData.begin() + offset + length);
|
||||
return true;
|
||||
}
|
||||
|
||||
Blob
|
||||
Serializer::getRaw(int offset, int length) const
|
||||
{
|
||||
Blob o;
|
||||
|
||||
if ((offset + length) > mData.size())
|
||||
return o;
|
||||
|
||||
o.assign(mData.begin() + offset, mData.begin() + offset + length);
|
||||
return o;
|
||||
}
|
||||
|
||||
uint256
|
||||
Serializer::getSHA512Half() const
|
||||
{
|
||||
@@ -278,99 +219,6 @@ Serializer::addVL(const void* ptr, int len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
Serializer::getVL(Blob& objectVL, int offset, int& length) const
|
||||
{
|
||||
int b1;
|
||||
|
||||
if (!get8(b1, offset++))
|
||||
return false;
|
||||
|
||||
int datLen, lenLen = decodeLengthLength(b1);
|
||||
|
||||
try
|
||||
{
|
||||
if (lenLen == 1)
|
||||
datLen = decodeVLLength(b1);
|
||||
else if (lenLen == 2)
|
||||
{
|
||||
int b2;
|
||||
|
||||
if (!get8(b2, offset++))
|
||||
return false;
|
||||
|
||||
datLen = decodeVLLength(b1, b2);
|
||||
}
|
||||
else if (lenLen == 3)
|
||||
{
|
||||
int b2, b3;
|
||||
|
||||
if (!get8(b2, offset++))
|
||||
return false;
|
||||
|
||||
if (!get8(b3, offset++))
|
||||
return false;
|
||||
|
||||
datLen = decodeVLLength(b1, b2, b3);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
length = lenLen + datLen;
|
||||
return getRaw(objectVL, offset, datLen);
|
||||
}
|
||||
|
||||
bool
|
||||
Serializer::getVLLength(int& length, int offset) const
|
||||
{
|
||||
int b1;
|
||||
|
||||
if (!get8(b1, offset++))
|
||||
return false;
|
||||
|
||||
int lenLen = decodeLengthLength(b1);
|
||||
|
||||
try
|
||||
{
|
||||
if (lenLen == 1)
|
||||
length = decodeVLLength(b1);
|
||||
else if (lenLen == 2)
|
||||
{
|
||||
int b2;
|
||||
|
||||
if (!get8(b2, offset++))
|
||||
return false;
|
||||
|
||||
length = decodeVLLength(b1, b2);
|
||||
}
|
||||
else if (lenLen == 3)
|
||||
{
|
||||
int b2, b3;
|
||||
|
||||
if (!get8(b2, offset++))
|
||||
return false;
|
||||
|
||||
if (!get8(b3, offset++))
|
||||
return false;
|
||||
|
||||
length = decodeVLLength(b1, b2, b3);
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (std::exception const&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
Serializer::addEncoded(int length)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user