//------------------------------------------------------------------------------ /* This file is part of Beast: https://github.com/vinniefalco/Beast Copyright 2013, Vinnie Falco Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ //============================================================================== #include #include #include #include #include #include #include namespace ripple { namespace detail { template class test_user_type_member { private: T t; public: explicit test_user_type_member(T const& t_ = T()) : t(t_) { } template friend void hash_append(Hasher& h, test_user_type_member const& a) noexcept { using beast::hash_append; hash_append(h, a.t); } }; template class test_user_type_free { private: T t; public: explicit test_user_type_free(T const& t_ = T()) : t(t_) { } template friend void hash_append(Hasher& h, test_user_type_free const& a) noexcept { using beast::hash_append; hash_append(h, a.t); } }; } // namespace detail } // namespace ripple //------------------------------------------------------------------------------ namespace ripple { namespace detail { template using test_hardened_unordered_set = std::unordered_set>; template using test_hardened_unordered_map = std::unordered_map>; template using test_hardened_unordered_multiset = std::unordered_multiset>; template using test_hardened_unordered_multimap = std::unordered_multimap>; } // namespace detail template class unsigned_integer { private: static_assert( std::is_integral::value && std::is_unsigned::value, "UInt must be an unsigned integral type"); static_assert( Bits % (8 * sizeof(UInt)) == 0, "Bits must be a multiple of 8*sizeof(UInt)"); static_assert( Bits >= (8 * sizeof(UInt)), "Bits must be at least 8*sizeof(UInt)"); static std::size_t const size = Bits / (8 * sizeof(UInt)); std::array m_vec; public: using value_type = UInt; static std::size_t const bits = Bits; static std::size_t const bytes = bits / 8; template static unsigned_integer from_number(Int v) { unsigned_integer result; for (std::size_t i(1); i < size; ++i) result.m_vec[i] = 0; result.m_vec[0] = v; return result; } void* data() noexcept { return &m_vec[0]; } void const* data() const noexcept { return &m_vec[0]; } template friend void hash_append(Hasher& h, unsigned_integer const& a) noexcept { using beast::hash_append; hash_append(h, a.m_vec); } friend std::ostream& operator<<(std::ostream& s, unsigned_integer const& v) { for (std::size_t i(0); i < size; ++i) s << std::hex << std::setfill('0') << std::setw(2 * sizeof(UInt)) << v.m_vec[i]; return s; } }; using sha256_t = unsigned_integer<256, std::size_t>; #ifndef __INTELLISENSE__ static_assert(sha256_t::bits == 256, "sha256_t must have 256 bits"); #endif } // namespace ripple //------------------------------------------------------------------------------ namespace ripple { class hardened_hash_test : public beast::unit_test::suite { public: template void check() { T t{}; hardened_hash<>()(t); pass(); } template