Skip to content

Commit

Permalink
address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sbiscigl committed May 21, 2024
1 parent fdcf989 commit 3e07631
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 52 deletions.
2 changes: 1 addition & 1 deletion cmake/external_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif()

# Encryption control
# TODO: BYO Crypto is not implemented for CRT/Was not working in the latest version of the SDK.
if(NOT NO_ENCRYPTION)
if(NO_ENCRYPTION)
message(FATAL_ERROR "BYO_CRYPTO is not currently implemented and has been broken since version 1.9")
set(ENABLE_INJECTED_ENCRYPTION ON)
message(STATUS "Encryption: None")
Expand Down
83 changes: 37 additions & 46 deletions src/aws-cpp-sdk-core/include/aws/core/utils/Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <aws/core/utils/memory/AWSMemory.h>
#include <aws/core/utils/memory/stl/AWSVector.h>
#include <aws/core/utils/memory/stl/AWSString.h>
#include <aws/crt/Types.h>
#include <memory>
#include <cassert>
Expand Down Expand Up @@ -39,7 +40,7 @@ namespace Aws
* Create new empty array of size arraySize. Default argument is 0. If it is empty then no allocation happens.
*/
Array(size_t arraySize = 0) :
m_size(arraySize),
m_capacity(arraySize),
m_length(arraySize),
m_data(arraySize > 0 ? Aws::MakeUniqueArray<T>(arraySize, ARRAY_ALLOCATION_TAG) : nullptr)
{
Expand All @@ -49,30 +50,25 @@ namespace Aws
* Create new array and initialize it to a raw array
*/
Array(const T* arrayToCopy, size_t arraySize) :
m_size(arraySize),
m_capacity(arraySize),
m_length(arraySize),
m_data(nullptr)
{
if (arrayToCopy != nullptr && m_size > 0)
if (arrayToCopy != nullptr && m_capacity > 0)
{
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));

#ifdef _WIN32
std::copy(arrayToCopy, arrayToCopy + arraySize, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
#else
m_data.reset(Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
std::copy(arrayToCopy, arrayToCopy + arraySize, m_data.get());
#endif // MSVC
}
}

/**
* Create new array with a pointer and its dimensions.
*/
Array(size_t m_size,
size_t m_length,
Array(size_t capacity,
size_t length,
UniqueArrayPtr<T> m_data)
: m_size(m_size),
m_length(m_length),
: m_capacity(capacity),
m_length(length),
m_data(std::move(m_data))
{
}
Expand All @@ -88,20 +84,16 @@ namespace Aws
totalSize += array->m_length;
}

m_size = totalSize;
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
m_capacity = totalSize;
m_data.reset(Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));

size_t location = 0;
for(auto& arr : toMerge)
{
if(arr->m_size > 0 && arr->m_data)
if(arr->m_capacity > 0 && arr->m_data)
{
size_t arraySize = arr->m_length;
#ifdef _WIN32
std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, stdext::checked_array_iterator< T * >(m_data.get() + location, m_length));
#else
std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, m_data.get() + location);
#endif // MSVC
location += arraySize;
}
}
Expand All @@ -110,29 +102,24 @@ namespace Aws

Array(const Array& other)
{
m_size = other.m_size;
m_capacity = other.m_capacity;
m_length = other.m_length;
m_data = nullptr;

if (m_size > 0)
if (m_capacity > 0)
{
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));

#ifdef _WIN32
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
#else
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get());
#endif // MSVC
m_data.reset(Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
std::copy(other.m_data.get(), other.m_data.get() + other.m_capacity, m_data.get());
}
}

//move c_tor
Array(Array&& other) noexcept:
m_size(other.m_size),
m_capacity(other.m_capacity),
m_length(other.m_length),
m_data(std::move(other.m_data))
{
other.m_size = 0;
other.m_capacity = 0;
other.m_data = nullptr;
}

Expand All @@ -145,39 +132,43 @@ namespace Aws
return *this;
}

m_size = other.m_size;
m_capacity = other.m_capacity;
m_length = other.m_length;
m_data = nullptr;

if (m_size > 0)
if (m_capacity > 0)
{
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));

#ifdef _WIN32
std::copy(other.m_data.get(), other.m_data.get() + other.m_length, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
#else
m_data.reset(Aws::NewArray<T>(m_capacity, ARRAY_ALLOCATION_TAG));
std::copy(other.m_data.get(), other.m_data.get() + other.m_length, m_data.get());
#endif // MSVC
}

return *this;
}

Array& operator=(Array&& other) noexcept
{
m_size = other.m_size;
m_capacity = other.m_capacity;
m_length = other.m_length;
m_data = std::move(other.m_data);

return *this;
}

Array(const Aws::String& string):
m_capacity(string.capacity()),
m_length(string.length()),
m_data(nullptr)
{
m_data.reset(Aws::NewArray<unsigned char>(m_capacity, ARRAY_ALLOCATION_TAG));
std::copy(string.c_str(), string.c_str() + string.length(), m_data.get());
}

bool operator==(const Array& other) const
{
if (this == &other)
return true;

if (m_size == 0 && other.m_size == 0)
if (m_capacity == 0 && other.m_capacity == 0)
{
return true;
}
Expand All @@ -187,7 +178,7 @@ namespace Aws
return false;
}

if (m_length == other.m_length && m_size == other.m_size && m_data && other.m_data)
if (m_length == other.m_length && m_capacity == other.m_capacity && m_data && other.m_data)
{
for (unsigned i = 0; i < m_length; ++i)
{
Expand Down Expand Up @@ -235,7 +226,7 @@ namespace Aws

inline size_t GetSize() const
{
return m_size;
return m_capacity;
}

inline T* GetUnderlyingData() const
Expand All @@ -249,7 +240,7 @@ namespace Aws
}

protected:
size_t m_size;
size_t m_capacity;
size_t m_length;
Aws::UniqueArrayPtr<T> m_data;
};
Expand All @@ -273,7 +264,7 @@ namespace Aws
CryptoBuffer& operator=(CryptoBuffer&& other) { ByteBuffer::operator=(std::move(other)); return *this; }

CryptoBuffer(Crt::ByteBuf&& other) noexcept : ByteBuffer(
other.len,
other.capacity,
other.len,
nullptr)
{
Expand All @@ -285,7 +276,7 @@ namespace Aws

CryptoBuffer& operator=(Crt::ByteBuf&& other) noexcept
{
m_size = other.len;
m_capacity = other.capacity;
m_length = other.len;
m_data.reset(other.buffer);
other.capacity = 0;
Expand Down
4 changes: 1 addition & 3 deletions src/aws-cpp-sdk-core/source/auth/signer/AWSAuthV4Signer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -560,9 +560,7 @@ Aws::Utils::ByteBuffer AWSAuthV4Signer::ComputeHash(const Aws::String& secretKey
{
Aws::String signingKey(Aws::Auth::AWSAuthHelper::SIGNING_KEY);
signingKey.append(secretKey);
auto kDate = HashingUtils::CalculateSHA256HMAC(
ByteBuffer((unsigned char *) simpleDate.c_str(), simpleDate.length()),
ByteBuffer((unsigned char *) signingKey.c_str(), signingKey.length()));
auto kDate = HashingUtils::CalculateSHA256HMAC(simpleDate, signingKey);

if (kDate.GetLength() == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ namespace Aws
void CRTSecureRandomBytes::GetBytes(unsigned char *buffer, std::size_t bufferSize)
{
auto outputBuf = Crt::ByteBufFromEmptyArray(buffer, bufferSize);
(void)Crt::Crypto::GenerateRandomBytes(outputBuf, bufferSize);
if (!Crt::Crypto::GenerateRandomBytes(outputBuf, bufferSize))
{
AWS_UNREACHABLE();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ namespace
static Aws::String GetTestContainerName()
{
// "-" is not allowed in container name, convert uuid to its hex.
static const std::string suffix = HashingUtils::HexEncode(ByteBuffer(Aws::Utils::UUID::RandomUUID())).c_str();
static const std::string suffix = HashingUtils::HexEncode(ByteBuffer(Aws::Utils::UUID::RandomUUID().operator ByteBuffer())).c_str();
Aws::StringStream ss;
ss << Aws::Testing::GetAwsResourcePrefix() << TEST_CONTAINER_NAME_BASE << suffix;
return Aws::Utils::StringUtils::ToLower(ss.str().c_str());
Expand Down

0 comments on commit 3e07631

Please sign in to comment.