Skip to content

Commit

Permalink
crypto: Spanify EllSwiftPubKey constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Sep 7, 2023
1 parent 5f4b2c6 commit dc2d7eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/pubkey.cpp
Expand Up @@ -336,6 +336,12 @@ bool CPubKey::Derive(CPubKey& pubkeyChild, ChainCode &ccChild, unsigned int nChi
return true;
}

EllSwiftPubKey::EllSwiftPubKey(Span<const std::byte> ellswift) noexcept
{
assert(ellswift.size() == SIZE);
std::copy(ellswift.begin(), ellswift.end(), m_pubkey.begin());
}

CPubKey EllSwiftPubKey::Decode() const
{
secp256k1_pubkey pubkey;
Expand Down
3 changes: 1 addition & 2 deletions src/pubkey.h
Expand Up @@ -303,8 +303,7 @@ struct EllSwiftPubKey
EllSwiftPubKey() noexcept = default;

/** Construct a new ellswift public key from a given serialization. */
EllSwiftPubKey(const std::array<std::byte, SIZE>& ellswift) :
m_pubkey(ellswift) {}
EllSwiftPubKey(Span<const std::byte> ellswift) noexcept;

/** Decode to normal compressed CPubKey (for debugging purposes). */
CPubKey Decode() const;
Expand Down
10 changes: 2 additions & 8 deletions src/test/bip324_tests.cpp
Expand Up @@ -38,14 +38,8 @@ void TestBIP324PacketVector(
{
// Convert input from hex to char/byte vectors/arrays.
const auto in_priv_ours = ParseHex(in_priv_ours_hex);
const auto in_ellswift_ours_vec = ParseHex<std::byte>(in_ellswift_ours_hex);
assert(in_ellswift_ours_vec.size() == 64);
std::array<std::byte, 64> in_ellswift_ours;
std::copy(in_ellswift_ours_vec.begin(), in_ellswift_ours_vec.end(), in_ellswift_ours.begin());
const auto in_ellswift_theirs_vec = ParseHex<std::byte>(in_ellswift_theirs_hex);
assert(in_ellswift_theirs_vec.size() == 64);
std::array<std::byte, 64> in_ellswift_theirs;
std::copy(in_ellswift_theirs_vec.begin(), in_ellswift_theirs_vec.end(), in_ellswift_theirs.begin());
const auto in_ellswift_ours = ParseHex<std::byte>(in_ellswift_ours_hex);
const auto in_ellswift_theirs = ParseHex<std::byte>(in_ellswift_theirs_hex);
const auto in_contents = ParseHex<std::byte>(in_contents_hex);
const auto in_aad = ParseHex<std::byte>(in_aad_hex);
const auto mid_send_garbage = ParseHex<std::byte>(mid_send_garbage_hex);
Expand Down

0 comments on commit dc2d7eb

Please sign in to comment.