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 15d472b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 51 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
84 changes: 38 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 capactiy,
size_t length,
UniqueArrayPtr<T> m_data)
: m_size(m_size),
m_length(m_length),
: m_capacity(capactiy),
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,44 @@ 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 +179,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 +227,7 @@ namespace Aws

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

inline T* GetUnderlyingData() const
Expand All @@ -249,7 +241,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 +265,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 +277,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

0 comments on commit 15d472b

Please sign in to comment.