From aea1aa149e7155c7edd30a34b4beaa746e13b0c3 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Wed, 27 Mar 2024 10:49:46 -0500 Subject: [PATCH] GH-2286 Remove const as FC_REFLECT does not support const members --- libraries/libfc/include/fc/crypto/bls_public_key.hpp | 12 ++++++------ libraries/libfc/src/crypto/bls_public_key.cpp | 8 +------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libraries/libfc/include/fc/crypto/bls_public_key.hpp b/libraries/libfc/include/fc/crypto/bls_public_key.hpp index f7e86b4717..7c9da88320 100644 --- a/libraries/libfc/include/fc/crypto/bls_public_key.hpp +++ b/libraries/libfc/include/fc/crypto/bls_public_key.hpp @@ -11,7 +11,8 @@ namespace fc::crypto::blslib { const std::string bls_public_key_prefix = "PUB_BLS_"; }; - // Immutable after construction. + // Immutable after construction (although operator= is provided) + // Atributes are not const because FC_REFLECT only works for non-const members. // Provides an efficient wrapper around bls12_381::g1. // Serialization form: // Non-Montgomery form and little-endian encoding for the field elements. @@ -22,9 +23,8 @@ namespace fc::crypto::blslib { bls_public_key() = default; bls_public_key(bls_public_key&&) = default; bls_public_key(const bls_public_key&) = default; - - // Would prefer to not have this to enforce immutablity. Needed so keys can be copied around. - bls_public_key& operator=(const bls_public_key& rhs); + bls_public_key& operator=(const bls_public_key& rhs) = default; + bls_public_key& operator=(bls_public_key&& rhs) = default; // throws if unable to convert to valid bls12_381::g1 explicit bls_public_key(std::span affine_non_montgomery_le); @@ -55,8 +55,8 @@ namespace fc::crypto::blslib { friend struct fc::has_reflector_init; void reflector_init(); - const std::array _affine_non_montgomery_le{}; - const bls12_381::g1 _jacobian_montgomery_le; // cached g1 + std::array _affine_non_montgomery_le{}; + bls12_381::g1 _jacobian_montgomery_le; // cached g1 }; } // fc::crypto::blslib diff --git a/libraries/libfc/src/crypto/bls_public_key.cpp b/libraries/libfc/src/crypto/bls_public_key.cpp index 4baee03b36..2ca3e014d2 100644 --- a/libraries/libfc/src/crypto/bls_public_key.cpp +++ b/libraries/libfc/src/crypto/bls_public_key.cpp @@ -39,12 +39,6 @@ namespace fc::crypto::blslib { , _jacobian_montgomery_le(from_affine_bytes_le(_affine_non_montgomery_le)) { } - bls_public_key& bls_public_key::operator=(const bls_public_key& rhs) { - const_cast&>(_affine_non_montgomery_le) = rhs._affine_non_montgomery_le; - const_cast(_jacobian_montgomery_le) = rhs._jacobian_montgomery_le; - return *this; - } - std::string bls_public_key::to_string() const { std::string data_str = fc::crypto::blslib::serialize_base64url>(_affine_non_montgomery_le); return config::bls_public_key_prefix + data_str; @@ -57,7 +51,7 @@ namespace fc::crypto::blslib { std::optional g1 = bls12_381::g1::fromAffineBytesLE(_affine_non_montgomery_le); FC_ASSERT(g1, "Invalid bls public key ${k}", ("k", _affine_non_montgomery_le)); // reflector_init is private and only called during construction - const_cast(_jacobian_montgomery_le) = *g1; + _jacobian_montgomery_le = *g1; } } // fc::crypto::blslib