Skip to content

Commit

Permalink
fix self-assignment on BNWrapper, as well as move construction and mo…
Browse files Browse the repository at this point in the history
…ve assignment. Bumps C++ version to 17
  • Loading branch information
arvidn authored and hoffmang9 committed Nov 4, 2020
1 parent 2ba6435 commit 891a75e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

IF(NOT CMAKE_BUILD_TYPE)
Expand Down
2 changes: 1 addition & 1 deletion js-bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14.0 FATAL_ERROR)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)

include_directories(
${INCLUDE_DIRECTORIES}
Expand Down
2 changes: 1 addition & 1 deletion python-bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 17)

# CMake 3.14+
include(FetchContent)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.14 FATAL_ERROR)
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD 17)

# CMake 3.14+
include(FetchContent)
Expand Down
26 changes: 19 additions & 7 deletions src/elements.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ extern "C" {
#include <gmp.h>
#endif

#include <utility>

namespace bls {
class G1Element;
class G2Element;
Expand Down Expand Up @@ -123,12 +125,9 @@ class GTElement {

class BNWrapper {
public:
bn_t *b;
bn_t *b = nullptr;

BNWrapper()
{
b = NULL;
}
BNWrapper() = default;

BNWrapper(const BNWrapper& other)
{
Expand All @@ -137,15 +136,28 @@ class BNWrapper {
bn_copy(*b, *(other.b));
}

BNWrapper& operator=(const BNWrapper& other)
BNWrapper(BNWrapper&& other)
: b(std::exchange(other.b, nullptr))
{}

BNWrapper& operator=(const BNWrapper& other) &
{
if (&other == this) return *this;
b = Util::SecAlloc<bn_t>(1);
bn_new(*b);
bn_copy(*b, *(other.b));
return *this;
}

~BNWrapper()
BNWrapper& operator=(BNWrapper&& other) &
{
if (&other == this) return *this;
if (b) Util::SecFree(b);
b = std::exchange(other.b, nullptr);
return *this;
}

~BNWrapper()
{
if(b != NULL) {
Util::SecFree(b);
Expand Down

0 comments on commit 891a75e

Please sign in to comment.