From 8c78985de2362fd9387ce8a602d6f3a16982c2a5 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 9 Jun 2019 02:56:30 -0400 Subject: [PATCH] Add ModularArithmetic::operator= --- modarith.h | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modarith.h b/modarith.h index aa90c8a5..c473e3d0 100644 --- a/modarith.h +++ b/modarith.h @@ -35,6 +35,9 @@ CRYPTOPP_DLL_TEMPLATE_CLASS AbstractEuclideanDomain; ///
    abcd = group.Add(a, group.Add(b, group.Add(c,d));
/// The following code will produce incorrect results: ///
    abcd = group.Add(group.Add(a,b), group.Add(c,d));
+/// \details If a ModularArithmetic is copied or assigned the modulus +/// is copied, but not the internal data members. The internal data +/// members are undefined after copy or assignment. /// \sa Integer on the /// Crypto++ wiki. class CRYPTOPP_DLL ModularArithmetic : public AbstractRing @@ -54,7 +57,18 @@ public: /// \brief Copy construct a ModularArithmetic /// \param ma other ModularArithmetic ModularArithmetic(const ModularArithmetic &ma) - : m_modulus(ma.m_modulus), m_result(static_cast(0), ma.m_modulus.reg.size()) {} + : m_modulus(ma.m_modulus), m_result(static_cast(0), m_modulus.reg.size()) {} + + /// \brief Assign a ModularArithmetic + /// \param ma other ModularArithmetic + ModularArithmetic& operator=(const ModularArithmetic &ma) { + if (this != &ma) + { + m_modulus = ma.m_modulus; + m_result = Integer(static_cast(0), m_modulus.reg.size()); + } + return *this; + } /// \brief Construct a ModularArithmetic /// \param bt BER encoded ModularArithmetic