diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp')
-rw-r--r-- | contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp new file mode 100644 index 0000000000..43e7863421 --- /dev/null +++ b/contrib/libs/aws-sdk-cpp/aws-cpp-sdk-core/source/utils/Array.cpp @@ -0,0 +1,65 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include <aws/core/utils/Array.h> + +#include <aws/core/platform/Security.h> + +namespace Aws +{ + namespace Utils + { + Array<CryptoBuffer> CryptoBuffer::Slice(size_t sizeOfSlice) const + { + assert(sizeOfSlice <= GetLength()); + + size_t numberOfSlices = (GetLength() + sizeOfSlice - 1) / sizeOfSlice; + size_t currentSliceIndex = 0; + Array<CryptoBuffer> slices(numberOfSlices); + + for (size_t i = 0; i < numberOfSlices - 1; ++i) + { + CryptoBuffer newArray(sizeOfSlice); + for (size_t cpyIdx = 0; cpyIdx < newArray.GetLength(); ++cpyIdx) + { + newArray[cpyIdx] = GetItem(cpyIdx + currentSliceIndex); + } + currentSliceIndex += sizeOfSlice; + slices[i] = std::move(newArray); + } + + CryptoBuffer lastArray(GetLength() % sizeOfSlice == 0 ? sizeOfSlice : GetLength() % sizeOfSlice ); + for (size_t cpyIdx = 0; cpyIdx < lastArray.GetLength(); ++cpyIdx) + { + lastArray[cpyIdx] = GetItem(cpyIdx + currentSliceIndex); + } + slices[slices.GetLength() - 1] = std::move(lastArray); + + return slices; + } + + CryptoBuffer& CryptoBuffer::operator^(const CryptoBuffer& operand) + { + size_t smallestSize = std::min<size_t>(GetLength(), operand.GetLength()); + for (size_t i = 0; i < smallestSize; ++i) + { + (*this)[i] ^= operand[i]; + } + + return *this; + } + + /** + * Zero out the array securely + */ + void CryptoBuffer::Zero() + { + if (GetUnderlyingData()) + { + Aws::Security::SecureMemClear(GetUnderlyingData(), GetLength()); + } + } + } +}
\ No newline at end of file |