mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
refactor: Return std::span from MakeByteSpan
In theory this commit should only touch the span.h header, because std::span can implicilty convert into Span in most places, if needed. However, at least when using the clang compiler, there are some false-positive lifetimebound warnings and some implicit conversions can not be resolved. Thus, this refactoring commit also changed the affected places to replace Span with std::span.
This commit is contained in:
parent
aa68ed27b8
commit
fa720b94be
8 changed files with 14 additions and 14 deletions
|
@ -22,8 +22,8 @@
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
BIP324Cipher::BIP324Cipher(const CKey& key, Span<const std::byte> ent32) noexcept :
|
BIP324Cipher::BIP324Cipher(const CKey& key, std::span<const std::byte> ent32) noexcept
|
||||||
m_key(key)
|
: m_key(key)
|
||||||
{
|
{
|
||||||
m_our_pubkey = m_key.EllSwiftCreate(ent32);
|
m_our_pubkey = m_key.EllSwiftCreate(ent32);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
BIP324Cipher() = delete;
|
BIP324Cipher() = delete;
|
||||||
|
|
||||||
/** Initialize a BIP324 cipher with specified key and encoding entropy (testing only). */
|
/** Initialize a BIP324 cipher with specified key and encoding entropy (testing only). */
|
||||||
BIP324Cipher(const CKey& key, Span<const std::byte> ent32) noexcept;
|
BIP324Cipher(const CKey& key, std::span<const std::byte> ent32) noexcept;
|
||||||
|
|
||||||
/** Initialize a BIP324 cipher with specified key (testing only). */
|
/** Initialize a BIP324 cipher with specified key (testing only). */
|
||||||
BIP324Cipher(const CKey& key, const EllSwiftPubKey& pubkey) noexcept;
|
BIP324Cipher(const CKey& key, const EllSwiftPubKey& pubkey) noexcept;
|
||||||
|
|
|
@ -402,12 +402,12 @@ void CDBIterator::SeekImpl(Span<const std::byte> key)
|
||||||
m_impl_iter->iter->Seek(slKey);
|
m_impl_iter->iter->Seek(slKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
Span<const std::byte> CDBIterator::GetKeyImpl() const
|
std::span<const std::byte> CDBIterator::GetKeyImpl() const
|
||||||
{
|
{
|
||||||
return MakeByteSpan(m_impl_iter->iter->key());
|
return MakeByteSpan(m_impl_iter->iter->key());
|
||||||
}
|
}
|
||||||
|
|
||||||
Span<const std::byte> CDBIterator::GetValueImpl() const
|
std::span<const std::byte> CDBIterator::GetValueImpl() const
|
||||||
{
|
{
|
||||||
return MakeByteSpan(m_impl_iter->iter->value());
|
return MakeByteSpan(m_impl_iter->iter->value());
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,8 +130,8 @@ private:
|
||||||
const std::unique_ptr<IteratorImpl> m_impl_iter;
|
const std::unique_ptr<IteratorImpl> m_impl_iter;
|
||||||
|
|
||||||
void SeekImpl(Span<const std::byte> key);
|
void SeekImpl(Span<const std::byte> key);
|
||||||
Span<const std::byte> GetKeyImpl() const;
|
std::span<const std::byte> GetKeyImpl() const;
|
||||||
Span<const std::byte> GetValueImpl() const;
|
std::span<const std::byte> GetValueImpl() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -353,7 +353,7 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EllSwiftPubKey::EllSwiftPubKey(Span<const std::byte> ellswift) noexcept
|
EllSwiftPubKey::EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept
|
||||||
{
|
{
|
||||||
assert(ellswift.size() == SIZE);
|
assert(ellswift.size() == SIZE);
|
||||||
std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());
|
std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());
|
||||||
|
|
|
@ -317,7 +317,7 @@ public:
|
||||||
EllSwiftPubKey() noexcept = default;
|
EllSwiftPubKey() noexcept = default;
|
||||||
|
|
||||||
/** Construct a new ellswift public key from a given serialization. */
|
/** Construct a new ellswift public key from a given serialization. */
|
||||||
EllSwiftPubKey(Span<const std::byte> ellswift) noexcept;
|
EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept;
|
||||||
|
|
||||||
/** Decode to normal compressed CPubKey (for debugging purposes). */
|
/** Decode to normal compressed CPubKey (for debugging purposes). */
|
||||||
CPubKey Decode() const;
|
CPubKey Decode() const;
|
||||||
|
|
|
@ -266,14 +266,14 @@ Span<std::byte> AsWritableBytes(Span<T> s) noexcept
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
Span<const std::byte> MakeByteSpan(V&& v) noexcept
|
auto MakeByteSpan(const V& v) noexcept
|
||||||
{
|
{
|
||||||
return AsBytes(Span{std::forward<V>(v)});
|
return std::as_bytes(std::span{v});
|
||||||
}
|
}
|
||||||
template <typename V>
|
template <typename V>
|
||||||
Span<std::byte> MakeWritableByteSpan(V&& v) noexcept
|
auto MakeWritableByteSpan(V&& v) noexcept
|
||||||
{
|
{
|
||||||
return AsWritableBytes(Span{std::forward<V>(v)});
|
return std::as_writable_bytes(std::span{std::forward<V>(v)});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions to safely cast basic byte pointers to unsigned char pointers.
|
// Helper functions to safely cast basic byte pointers to unsigned char pointers.
|
||||||
|
|
|
@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
|
||||||
constexpr std::string_view out_exp{"04678afdb0"};
|
constexpr std::string_view out_exp{"04678afdb0"};
|
||||||
constexpr std::span in_s{HEX_PARSE_OUTPUT, out_exp.size() / 2};
|
constexpr std::span in_s{HEX_PARSE_OUTPUT, out_exp.size() / 2};
|
||||||
const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
|
const Span<const uint8_t> in_u{MakeUCharSpan(in_s)};
|
||||||
const Span<const std::byte> in_b{MakeByteSpan(in_s)};
|
const std::span<const std::byte> in_b{MakeByteSpan(in_s)};
|
||||||
|
|
||||||
BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
|
BOOST_CHECK_EQUAL(HexStr(in_u), out_exp);
|
||||||
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
|
BOOST_CHECK_EQUAL(HexStr(in_s), out_exp);
|
||||||
|
|
Loading…
Add table
Reference in a new issue