Modernize base_uint:

*  Add construction and assignment from a generic
   contiguous container.  Both compile-time and run time
   safety checks are made to ensure the safety of this
   conversion.

*  Remove base_uint::copyFrom.  The generic copy assignment
   operator now does this functionality with enhanced
   safety and better syntax.

*  Remove construction from and dedendence on Blob.
   The generic constructor and assignment now handle this
   functionality.

*  Fix client code to adhere to this new API.

*  Removed the use of fromVoid in PeerImp.cpp as it was
   an inappropriate use of this dangerous API.  The
   generic container constructors do it with enhanced
   safety and better syntax.

*  Rename data member pn to data_ and make it private.

*  Remove constraint from hash_append

*  Remove array_type alias
This commit is contained in:
Howard Hinnant
2019-05-23 19:29:25 -04:00
committed by Manoj doshi
parent de99e79bf1
commit 773dcd1d48
18 changed files with 105 additions and 74 deletions

View File

@@ -18,9 +18,11 @@
//==============================================================================
#include <ripple/basics/base_uint.h>
#include <ripple/basics/Blob.h>
#include <ripple/basics/hardened_hash.h>
#include <ripple/beast/unit_test.h>
#include <boost/algorithm/string.hpp>
#include <complex>
#include <type_traits>
@@ -57,6 +59,8 @@ struct base_uint_test : beast::unit_test::suite
void run() override
{
static_assert(!std::is_constructible<test96, std::complex<double>>::value, "");
static_assert(!std::is_assignable<test96&, std::complex<double>>::value, "");
// used to verify set insertion (hashing required)
std::unordered_set<test96, hardened_hash<>> uset;

View File

@@ -77,7 +77,7 @@ public:
{
blob b;
hex_to_binary (s.begin (), s.end (), b);
return uint256::fromVoid(b.data());
return uint256{b};
}
static

View File

@@ -22,6 +22,7 @@
#include <ripple/beast/xor_shift_engine.h>
#include <ripple/beast/unit_test.h>
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <numeric>
@@ -115,12 +116,12 @@ public:
digest_test ()
{
beast::xor_shift_engine g(19207813);
std::uint8_t buf[32];
std::array<std::uint8_t, 32> buf;
for (int i = 0; i < 1000000; i++)
{
beast::rngfill (buf, sizeof(buf), g);
dataset1.push_back (uint256::fromVoid (buf));
beast::rngfill (buf.data(), buf.size(), g);
dataset1.push_back (uint256{buf});
}
}