LibCrypto: Allow moving SignedBigInteger / UnsignedBigInteger

We defined copy operations but not move operations, so every existing
move() resulted in a copy.
This commit is contained in:
Timothy Flynn
2025-07-21 07:31:33 -04:00
committed by Jelle Raaijmakers
parent cd73c70ad6
commit 8600c5149b
Notes: github-actions[bot] 2025-07-21 13:23:41 +00:00
5 changed files with 69 additions and 0 deletions

View File

@@ -52,6 +52,14 @@ SignedBigInteger::SignedBigInteger(SignedBigInteger const& other)
MP_MUST(mp_init_copy(&m_mp, &other.m_mp));
}
SignedBigInteger::SignedBigInteger(SignedBigInteger&& other)
: m_mp(other.m_mp)
, m_hash(other.m_hash)
{
other.m_mp = {};
other.m_hash.clear();
}
SignedBigInteger& SignedBigInteger::operator=(SignedBigInteger const& other)
{
if (this == &other)
@@ -64,6 +72,21 @@ SignedBigInteger& SignedBigInteger::operator=(SignedBigInteger const& other)
return *this;
}
SignedBigInteger& SignedBigInteger::operator=(SignedBigInteger&& other)
{
if (this == &other)
return *this;
mp_clear(&m_mp);
m_mp = other.m_mp;
m_hash = other.m_hash;
other.m_mp = {};
other.m_hash.clear();
return *this;
}
SignedBigInteger::SignedBigInteger()
{
MP_MUST(mp_init(&m_mp));