Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions prefetch_crt_dependency.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
# SPDX-License-Identifier: Apache-2.0.

CRT_URI_PREFIX=https://codeload.github.com/awslabs
CRT_URI=${CRT_URI_PREFIX}/aws-crt-cpp/zip/72f84bc327462f405c4994228fffe1eeb16cca72 # v0.42.2
CRT_URI=${CRT_URI_PREFIX}/aws-crt-cpp/zip/0463563f9f656a493ec22ca962c2464bc8b831ab # v0.43.2

AWS_C_AUTH_URI=${CRT_URI_PREFIX}/aws-c-auth/zip/4b5d524bf1a511b05e0fffe5bdc51800770b9427 # v0.10.4
AWS_C_CAL_URI=${CRT_URI_PREFIX}/aws-c-cal/zip/9edd8eac2b21ca6a04535b91d60d361c2f1bb60f # v0.9.14
AWS_C_CAL_URI=${CRT_URI_PREFIX}/aws-c-cal/zip/8aa2a48a09f93c65d4cf06388e143a6584de6321 # v0.9.15
AWS_C_COMMON_URI=${CRT_URI_PREFIX}/aws-c-common/zip/3c69b871dfa1815231802febf1bb6899f84cccdb # v0.14.3
AWS_C_COMPRESSION_URI=${CRT_URI_PREFIX}/aws-c-compression/zip/d8264e64f698341eb03039b96b4f44702a9b3f83 # v0.3.2
AWS_C_EVENT_STREAM_URI=${CRT_URI_PREFIX}/aws-c-event-stream/zip/51bef3c44e1058b1689751539170b2e0f589ccdb # v0.7.1
AWS_C_HTTP_URI=${CRT_URI_PREFIX}/aws-c-http/zip/8aefd899fc3210bfd0e3fd414011a3cb708bf6e4 # v0.11.0
AWS_C_IO_URI=${CRT_URI_PREFIX}/aws-c-io/zip/54350963b64dfc6c4b0ea623b08aa252aae3d7d7 # v0.27.4
AWS_C_IO_URI=${CRT_URI_PREFIX}/aws-c-io/zip/e2946c99521fa12d285c9a0829c92b1bf713922b # v0.27.5
AWS_C_MQTT_URI=${CRT_URI_PREFIX}/aws-c-mqtt/zip/2ef9605ec9c50bea3f921e08022ddd57eed70901 # v0.16.0
AWS_C_S3_URI=${CRT_URI_PREFIX}/aws-c-s3/zip/1f29ef8871a27dc8b90325418780659bac534d71 # v0.13.1
AWS_C_SDKUTILS_URI=${CRT_URI_PREFIX}/aws-c-sdkutils/zip/cb14fea362c82c995eebd34e2e96590ab4e0ed58 # v0.2.7
AWS_C_S3_URI=${CRT_URI_PREFIX}/aws-c-s3/zip/a852faa2df3ab2b31fb4cfd64fd3379a2f4ae22e # v0.13.2
AWS_C_SDKUTILS_URI=${CRT_URI_PREFIX}/aws-c-sdkutils/zip/528b9dfff4a804b334875ecf8a0471f7d1366f24 # v0.2.8
AWS_CHECKSUMS_URI=${CRT_URI_PREFIX}/aws-checksums/zip/1d5f2f1f3e5d013aae8810878ceb5b3f6f258c4e # v0.2.10
AWS_LC_URI=${CRT_URI_PREFIX}/aws-lc/zip/683ebde4bf3bcc016a9a710ad6b49c0c91b59161 # v5.2.0
S2N_URI=${CRT_URI_PREFIX}/s2n/zip/f5f6c6c2ce2370de1aa3ade6899a7321d1127bb8 # v1.7.5
AWS_LC_URI=${CRT_URI_PREFIX}/aws-lc/zip/f6acf748df0ea6157d55e640730b38d21a7751cd # v5.4.0
S2N_URI=${CRT_URI_PREFIX}/s2n/zip/66b1c94d1dfc99b237427cbde230eca63bb8b89c # v1.7.6


echo "Removing CRT"
Expand Down
5 changes: 0 additions & 5 deletions src/aws-cpp-sdk-core/include/aws/core/utils/base64/Base64.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ namespace Aws
* Calculates the length of an encoded base64 string based on the buffer being encoded
*/
static size_t CalculateBase64EncodedLength(const ByteBuffer& buffer);

private:
char m_mimeBase64EncodingTable[64];
uint8_t m_mimeBase64DecodingTable[256];

};

} // namespace Base64
Expand Down
152 changes: 26 additions & 126 deletions src/aws-cpp-sdk-core/source/utils/base64/Base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,146 +3,46 @@
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/core/utils/UnreferencedParam.h>
#include <aws/core/utils/base64/Base64.h>
#include <cstring>
#include <aws/crt/Types.h>

using namespace Aws::Utils::Base64;

static const uint8_t SENTINEL_VALUE = 255;
static const char BASE64_ENCODING_TABLE_MIME[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
namespace Aws {
namespace Utils {
namespace Base64 {

namespace Aws
{
namespace Utils
{
namespace Base64
{

Base64::Base64(const char *encodingTable)
{
if(encodingTable == nullptr)
{
encodingTable = BASE64_ENCODING_TABLE_MIME;
}

size_t encodingTableLength = strlen(encodingTable);
if(encodingTableLength != 64)
{
encodingTable = BASE64_ENCODING_TABLE_MIME;
encodingTableLength = 64;
}

memcpy(m_mimeBase64EncodingTable, encodingTable, encodingTableLength);

memset((void *)m_mimeBase64DecodingTable, 0, 256);

for(uint32_t i = 0; i < encodingTableLength; ++i)
{
uint32_t index = static_cast<uint32_t>(m_mimeBase64EncodingTable[i]);
m_mimeBase64DecodingTable[index] = static_cast<uint8_t>(i);
}

m_mimeBase64DecodingTable[(uint32_t)'='] = SENTINEL_VALUE;
namespace {
Aws::Crt::ByteCursor AsCursor(const Aws::Utils::ByteBuffer& buffer) {
return Aws::Crt::ByteCursorFromArray(buffer.GetUnderlyingData(), buffer.GetLength());
}

Aws::String Base64::Encode(const Aws::Utils::ByteBuffer& buffer) const
{
size_t bufferLength = buffer.GetLength();
size_t blockCount = (bufferLength + 2) / 3;
size_t remainderCount = (bufferLength % 3);

Aws::String outputString;
outputString.reserve(CalculateBase64EncodedLength(buffer));

for(size_t i = 0; i < bufferLength; i += 3 )
{
uint32_t block = buffer[ i ];

block <<= 8;
if (i + 1 < bufferLength)
{
block = block | buffer[ i + 1 ];
}

block <<= 8;
if (i + 2 < bufferLength)
{
block = block | buffer[ i + 2 ];
}

outputString.push_back(m_mimeBase64EncodingTable[(block >> 18) & 0x3F]);
outputString.push_back(m_mimeBase64EncodingTable[(block >> 12) & 0x3F]);
outputString.push_back(m_mimeBase64EncodingTable[(block >> 6) & 0x3F]);
outputString.push_back(m_mimeBase64EncodingTable[block & 0x3F]);
}

if(remainderCount > 0)
{
outputString[blockCount * 4 - 1] = '=';
if(remainderCount == 1)
{
outputString[blockCount * 4 - 2] = '=';
}
}

return outputString;
Aws::Crt::ByteCursor AsCursor(const Aws::String& str) {
return Aws::Crt::ByteCursorFromArray(reinterpret_cast<const uint8_t*>(str.data()), str.length());
}
} // namespace

Aws::Utils::ByteBuffer Base64::Decode(const Aws::String& str) const
{
size_t decodedLength = CalculateBase64DecodedLength(str);

Aws::Utils::ByteBuffer buffer(decodedLength);

const char* rawString = str.c_str();
size_t blockCount = str.length() / 4;
for(size_t i = 0; i < blockCount; ++i)
{
size_t stringIndex = i * 4;
Base64::Base64(const char* encodingTable) { AWS_UNREFERENCED_PARAM(encodingTable); }

uint32_t value1 = m_mimeBase64DecodingTable[uint32_t(rawString[stringIndex])];
uint32_t value2 = m_mimeBase64DecodingTable[uint32_t(rawString[++stringIndex])];
uint32_t value3 = m_mimeBase64DecodingTable[uint32_t(rawString[++stringIndex])];
uint32_t value4 = m_mimeBase64DecodingTable[uint32_t(rawString[++stringIndex])];

size_t bufferIndex = i * 3;
buffer[bufferIndex] = static_cast<uint8_t>((value1 << 2) | ((value2 >> 4) & 0x03));
if(value3 != SENTINEL_VALUE)
{
buffer[++bufferIndex] = static_cast<uint8_t>(((value2 << 4) & 0xF0) | ((value3 >> 2) & 0x0F));
if(value4 != SENTINEL_VALUE)
{
buffer[++bufferIndex] = static_cast<uint8_t>((value3 & 0x03) << 6 | value4);
}
}
}

return buffer;
Aws::String Base64::Encode(const Aws::Utils::ByteBuffer& buffer) const {
const auto encoded = Aws::Crt::Base64Encode(AsCursor(buffer));
return {encoded.data(), encoded.size()};
}

size_t Base64::CalculateBase64DecodedLength(const Aws::String& b64input)
{
const size_t len = b64input.length();
if(len < 2)
{
return 0;
}

size_t padding = 0;

if (b64input[len - 1] == '=' && b64input[len - 2] == '=') //last two chars are =
padding = 2;
else if (b64input[len - 1] == '=') //last char is =
padding = 1;
Aws::Utils::ByteBuffer Base64::Decode(const Aws::String& str) const {
const auto decoded = Aws::Crt::Base64Decode(AsCursor(str));
return {decoded.data(), decoded.size()};
}

return (len * 3 / 4 - padding);
size_t Base64::CalculateBase64EncodedLength(const Aws::Utils::ByteBuffer& buffer) {
return Aws::Crt::Base64EncodedLength(AsCursor(buffer));
}

size_t Base64::CalculateBase64EncodedLength(const Aws::Utils::ByteBuffer& buffer)
{
return 4 * ((buffer.GetLength() + 2) / 3);
size_t Base64::CalculateBase64DecodedLength(const Aws::String& b64input) {
return Aws::Crt::Base64DecodedLength(AsCursor(b64input));
}

} // namespace Base64
} // namespace Utils
} // namespace Aws
} // namespace Base64
} // namespace Utils
} // namespace Aws
19 changes: 19 additions & 0 deletions tests/aws-cpp-sdk-core-tests/utils/HashingUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <aws/testing/AwsCppSdkGTestSuite.h>

#include <aws/core/utils/HashingUtils.h>
#include <aws/core/utils/base64/Base64.h>
#include <aws/core/utils/memory/stl/AWSStringStream.h>


Expand Down Expand Up @@ -68,6 +69,24 @@ TEST_F(HashingUtilsTest, TestBase64Decoding)
ASSERT_EQ(ByteBuffer((unsigned char*) "foobar", 6), test7);
}

TEST_F(HashingUtilsTest, TestBase64DecodeNeverWritesMoreThanCalculatedLength)
{
Aws::Vector<Aws::String> inputs = {"", "X", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy",
"AAAA=", "AAAAA=", "AAAAAA=", "AAAAAAA=", "AB=D", "=", "==", "===", "====",
"A===", "AA==", "AAA=", "//++", "AAAA"};
for (int byte = 0x80; byte <= 0xFF; ++byte)
{
inputs.emplace_back(Aws::String{static_cast<char>(byte)} + "AAA");
}

for (const auto& input : inputs)
{
ASSERT_LE(HashingUtils::Base64Decode(input).GetLength(),
Aws::Utils::Base64::Base64::CalculateBase64DecodedLength(input))
<< "input: " << input;
}
}

TEST_F(HashingUtilsTest, TestHexEncodingDecoding)
{
unsigned char beforeHexEncoding[32] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@
#set($epBuiltInClassName = "${metadata.classNamePrefix}BuiltInParameters")
#set($exportMacro = "${CppViewHelper.computeExportValue($metadata.classNamePrefix)}")
#set($externMacro = "AWS_${metadata.classNamePrefix.toUpperCase()}_EXTERN")
#if($serviceModel.skipEndpointRulesBlob)
#set($epProviderType = "BDDEndpointProvider")
#else
#set($epProviderType = "DefaultEndpointProvider")
#end
#pragma once
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}_EXPORTS.h>
#if($serviceModel.hasServiceSpecificClientConfig())
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}ClientConfiguration.h>
#else
\#include <aws/core/client/GenericClientConfiguration.h>
#end
\#include <aws/core/endpoint/DefaultEndpointProvider.h>
\#include <aws/core/endpoint/${epProviderType}.h>
\#include <aws/core/endpoint/EndpointParameter.h>
\#include <aws/core/utils/memory/stl/AWSString.h>
\#include <aws/core/utils/memory/stl/AWSVector.h>
Expand All @@ -33,7 +38,7 @@ using ${metadata.classNamePrefix}ClientConfiguration = Aws::${serviceNamespace}:
#end
using EndpointParameters = Aws::Endpoint::EndpointParameters;
using Aws::Endpoint::EndpointProviderBase;
using Aws::Endpoint::DefaultEndpointProvider;
using Aws::Endpoint::${epProviderType};

#if ($serviceModel.endpointRules)
#if ($serviceModel.clientContextParams)
Expand Down Expand Up @@ -92,7 +97,7 @@ using ${metadata.classNamePrefix}EndpointProviderBase =
EndpointProviderBase<${metadata.classNamePrefix}ClientConfiguration, ${epBuiltInClassName}, ${epContextClassName}>;

using ${metadata.classNamePrefix}DefaultEpProviderBase =
DefaultEndpointProvider<${metadata.classNamePrefix}ClientConfiguration, ${epBuiltInClassName}, ${epContextClassName}>;
${epProviderType}<${metadata.classNamePrefix}ClientConfiguration, ${epBuiltInClassName}, ${epContextClassName}>;

#if($serviceModel.hasServiceSpecificClientConfig() || $serviceModel.clientContextParams)
} // namespace Endpoint
Expand All @@ -107,7 +112,7 @@ ${externMacro} template class ${exportMacro}
Aws::Endpoint::EndpointProviderBase<${serviceNamespace}::Endpoint::${metadata.classNamePrefix}ClientConfiguration, ${serviceNamespace}::Endpoint::${epBuiltInClassName}, ${serviceNamespace}::Endpoint::${epContextClassName}>;

${externMacro} template class ${exportMacro}
Aws::Endpoint::DefaultEndpointProvider<${serviceNamespace}::Endpoint::${metadata.classNamePrefix}ClientConfiguration, ${serviceNamespace}::Endpoint::${epBuiltInClassName}, ${serviceNamespace}::Endpoint::${epContextClassName}>;
Aws::Endpoint::${epProviderType}<${serviceNamespace}::Endpoint::${metadata.classNamePrefix}ClientConfiguration, ${serviceNamespace}::Endpoint::${epBuiltInClassName}, ${serviceNamespace}::Endpoint::${epContextClassName}>;
} // namespace Endpoint

namespace ${serviceNamespace}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#set($endpointPrefix = $metadata.endpointPrefix)
#set($epContextClassName = "${metadata.classNamePrefix}ClientContextParameters")
#set($epBuiltInClassName = "${metadata.classNamePrefix}BuiltInParameters")
#if($serviceModel.skipEndpointRulesBlob)
#set($epProviderType = "BDDEndpointProvider")
#else
#set($epProviderType = "DefaultEndpointProvider")
#end
\#include <aws/${metadata.projectName}/${metadata.classNamePrefix}EndpointProvider.h>
#if ($serviceModel.endpointRules)
\#include <aws/${metadata.projectName}/internal/${metadata.classNamePrefix}EndpointRules.h>
Expand All @@ -24,7 +29,7 @@ template class Aws::Endpoint::EndpointProviderBase<${serviceNamespace}::Endpoint
${serviceNamespace}::Endpoint::${epBuiltInClassName},
${serviceNamespace}::Endpoint::${epContextClassName}>;

template class Aws::Endpoint::DefaultEndpointProvider<${serviceNamespace}::Endpoint::${metadata.classNamePrefix}ClientConfiguration,
template class Aws::Endpoint::${epProviderType}<${serviceNamespace}::Endpoint::${metadata.classNamePrefix}ClientConfiguration,
${serviceNamespace}::Endpoint::${epBuiltInClassName},
${serviceNamespace}::Endpoint::${epContextClassName}>;
} // namespace Endpoint
Expand Down
19 changes: 19 additions & 0 deletions tools/code-generation/smithy/cpp-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ tasks.register("generate-smithy-build") {
val c2jMapStr: String = project.findProperty("c2jMap")?.toString() ?: "{}"
val namespaceMappings: String = project.findProperty("namespaceMappings")?.toString() ?: "{}"
val generateModels: Boolean = project.findProperty("generateModels")?.toString()?.toBoolean() ?: false
val generateEndpointRules: Boolean = project.findProperty("generateEndpointRules")?.toString()?.toBoolean() ?: false
val bddBytecoderPath: String = project.findProperty("bddBytecoderPath")?.toString() ?: ""
val pythonExecutable: String = project.findProperty("pythonExecutable")?.toString() ?: "python3"

fileTree(models).filter { it.isFile }.files.forEach eachFile@{ file ->
val model = Model.assembler()
Expand Down Expand Up @@ -74,6 +77,14 @@ tasks.register("generate-smithy-build") {
.withMember("namespaceMappings", Node.from(namespaceMappings))
.build())
}
if (generateEndpointRules) {
pluginsNode = pluginsNode.withMember("smithy-cpp-codegen-endpoint-rules", Node.objectNodeBuilder()
.withMember("c2jMap", Node.from(c2jMapStr))
.withMember("namespaceMappings", Node.from(namespaceMappings))
.withMember("bddBytecoderPath", Node.from(bddBytecoderPath))
.withMember("pythonExecutable", Node.from(pythonExecutable))
.build())
}

val projectionContents = Node.objectNodeBuilder()
.withMember("imports", Node.fromStrings("${models.absolutePath}${File.separator}${file.name}"))
Expand Down Expand Up @@ -127,6 +138,14 @@ tasks.register("generate-smithy-build") {
.withMember("namespaceMappings", Node.from(namespaceMappings))
.build())
}
if (generateEndpointRules) {
s3CrtPluginsNode = s3CrtPluginsNode.withMember("smithy-cpp-codegen-endpoint-rules", Node.objectNodeBuilder()
.withMember("c2jMap", Node.from(c2jMapStr))
.withMember("namespaceMappings", Node.from(namespaceMappings))
.withMember("bddBytecoderPath", Node.from(bddBytecoderPath))
.withMember("pythonExecutable", Node.from(pythonExecutable))
.build())
}
val s3CrtProjectionContents = Node.objectNodeBuilder()
.withMember("imports", Node.fromStrings(s3ModelFile.absolutePath))
.withMember("plugins", s3CrtPluginsNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public static String capitalize(String str) {
}

// Match C2jModelToGeneratorModelTransformer.sanitizeServiceAbbreviation() exactly
private static String sanitizeServiceAbbreviation(String serviceAbbreviation) {
public static String sanitizeServiceAbbreviation(String serviceAbbreviation) {
return serviceAbbreviation.replace(" ", "").replace("-", "").replace("_", "").replace("Amazon", "").replace("AWS", "").replace("/", "");
}

Expand Down Expand Up @@ -165,6 +165,19 @@ public static String getExportMacro(ServiceShape service, Map<String, String> se
return "AWS_" + serviceName.toUpperCase() + "_API";
}

/**
* Returns the hidden-visibility macro for a service (e.g., "AWS_KINESIS_LOCAL").
* Follows C2J convention: AWS_{UPPERCASED_SERVICE_NAME}_LOCAL
*
* @param service The service shape to generate the macro for
* @param serviceMap Service ID mappings for namespace overrides (reserved for future consistency with getSmithyServiceName)
* @return The local macro in format AWS_{SERVICE_NAME}_LOCAL
*/
public static String getLocalMacro(ServiceShape service, Map<String, String> serviceMap) {
String serviceName = getServiceName(service);
return "AWS_" + serviceName.toUpperCase() + "_LOCAL";
}

public static boolean isS3CrtProjection(ServiceShape service) {
String serviceId = service.getTrait(ServiceTrait.class)
.map(ServiceTrait::getSdkId)
Expand Down
Loading
Loading