Skip to content

Commit 2b5e6ef

Browse files
committed
refactor: Make XOnlyPubKey tolerate constexpr std::arrays
Length was already asserted inside of base_blob-ctor.
1 parent 403d86f commit 2b5e6ef

File tree

2 files changed

+1
-7
lines changed

2 files changed

+1
-7
lines changed

src/pubkey.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,6 @@ int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned
193193
static const std::vector<unsigned char> NUMS_H_DATA{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")};
194194
const XOnlyPubKey XOnlyPubKey::NUMS_H{NUMS_H_DATA};
195195

196-
XOnlyPubKey::XOnlyPubKey(Span<const unsigned char> bytes)
197-
{
198-
assert(bytes.size() == 32);
199-
std::copy(bytes.begin(), bytes.end(), m_keydata.begin());
200-
}
201-
202196
std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
203197
{
204198
std::vector<CKeyID> out;

src/pubkey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ class XOnlyPubKey
254254
bool IsNull() const { return m_keydata.IsNull(); }
255255

256256
/** Construct an x-only pubkey from exactly 32 bytes. */
257-
explicit XOnlyPubKey(Span<const unsigned char> bytes);
257+
constexpr explicit XOnlyPubKey(std::span<const unsigned char> bytes) : m_keydata{bytes} {}
258258

259259
/** Construct an x-only pubkey from a normal pubkey. */
260260
explicit XOnlyPubKey(const CPubKey& pubkey) : XOnlyPubKey(Span{pubkey}.subspan(1, 32)) {}

0 commit comments

Comments
 (0)