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:
MarcoFalke 2024-12-17 19:55:45 +01:00
parent aa68ed27b8
commit fa720b94be
No known key found for this signature in database
8 changed files with 14 additions and 14 deletions

View file

@ -22,8 +22,8 @@
#include <iterator>
#include <string>
BIP324Cipher::BIP324Cipher(const CKey& key, Span<const std::byte> ent32) noexcept :
m_key(key)
BIP324Cipher::BIP324Cipher(const CKey& key, std::span<const std::byte> ent32) noexcept
: m_key(key)
{
m_our_pubkey = m_key.EllSwiftCreate(ent32);
}

View file

@ -45,7 +45,7 @@ public:
BIP324Cipher() = delete;
/** 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). */
BIP324Cipher(const CKey& key, const EllSwiftPubKey& pubkey) noexcept;

View file

@ -402,12 +402,12 @@ void CDBIterator::SeekImpl(Span<const std::byte> key)
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());
}
Span<const std::byte> CDBIterator::GetValueImpl() const
std::span<const std::byte> CDBIterator::GetValueImpl() const
{
return MakeByteSpan(m_impl_iter->iter->value());
}

View file

@ -130,8 +130,8 @@ private:
const std::unique_ptr<IteratorImpl> m_impl_iter;
void SeekImpl(Span<const std::byte> key);
Span<const std::byte> GetKeyImpl() const;
Span<const std::byte> GetValueImpl() const;
std::span<const std::byte> GetKeyImpl() const;
std::span<const std::byte> GetValueImpl() const;
public:

View file

@ -353,7 +353,7 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
return true;
}
EllSwiftPubKey::EllSwiftPubKey(Span<const std::byte> ellswift) noexcept
EllSwiftPubKey::EllSwiftPubKey(std::span<const std::byte> ellswift) noexcept
{
assert(ellswift.size() == SIZE);
std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());

View file

@ -317,7 +317,7 @@ public:
EllSwiftPubKey() noexcept = default;
/** 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). */
CPubKey Decode() const;

View file

@ -266,14 +266,14 @@ Span<std::byte> AsWritableBytes(Span<T> s) noexcept
}
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>
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.

View file

@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(util_HexStr)
constexpr std::string_view out_exp{"04678afdb0"};
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 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_s), out_exp);