Skip to content

Commit

Permalink
refactor: Make XOnlyPubKey tolerate constexpr std::arrays
Browse files Browse the repository at this point in the history
Length was already asserted inside of base_blob-ctor.
  • Loading branch information
hodlinator committed Aug 28, 2024
1 parent 403d86f commit 2b5e6ef
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 7 deletions.
6 changes: 0 additions & 6 deletions src/pubkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ int ecdsa_signature_parse_der_lax(secp256k1_ecdsa_signature* sig, const unsigned
static const std::vector<unsigned char> NUMS_H_DATA{ParseHex("50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0")};
const XOnlyPubKey XOnlyPubKey::NUMS_H{NUMS_H_DATA};

XOnlyPubKey::XOnlyPubKey(Span<const unsigned char> bytes)
{
assert(bytes.size() == 32);
std::copy(bytes.begin(), bytes.end(), m_keydata.begin());
}

std::vector<CKeyID> XOnlyPubKey::GetKeyIDs() const
{
std::vector<CKeyID> out;
Expand Down
2 changes: 1 addition & 1 deletion src/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class XOnlyPubKey
bool IsNull() const { return m_keydata.IsNull(); }

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

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

0 comments on commit 2b5e6ef

Please sign in to comment.