refactor(Core): remove ace_autoptr, cleanup (#3276)

This commit is contained in:
Viste
2020-08-25 13:52:22 +03:00
committed by GitHub
parent 208c257b99
commit a9b90c9a07
7 changed files with 46 additions and 42 deletions

View File

@@ -10,7 +10,6 @@
#include <openssl/bn.h>
#include <openssl/crypto.h>
#include <algorithm>
#include <ace/Auto_Ptr.h>
BigNumber::BigNumber()
: _bn(BN_new())
@@ -158,23 +157,24 @@ bool BigNumber::isZero() const
return BN_is_zero(_bn);
}
ACE_Auto_Array_Ptr<uint8> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
std::unique_ptr<uint8[]> BigNumber::AsByteArray(int32 minSize, bool littleEndian)
{
int length = (minSize >= GetNumBytes()) ? minSize : GetNumBytes();
int numBytes = GetNumBytes();
int length = (minSize >= numBytes) ? minSize : numBytes;
uint8* array = new uint8[length];
// If we need more bytes than length of BigNumber set the rest to 0
if (length > GetNumBytes())
if (length > numBytes)
memset((void*)array, 0, length);
BN_bn2bin(_bn, (unsigned char *)array);
BN_bn2bin(_bn, (unsigned char*)array);
// openssl's BN stores data internally in big endian format, reverse if little endian desired
if (littleEndian)
std::reverse(array, array + length);
ACE_Auto_Array_Ptr<uint8> ret(array);
std::unique_ptr<uint8[]> ret(array);
return ret;
}