Skip to content

Commit

Permalink
Add string array as an option for request context params for endpoint…
Browse files Browse the repository at this point in the history
… resolution (#276)

Co-authored-by: Waqar Ahmed Khan <waahm7@gmail.com>
  • Loading branch information
DmitriyMusatkin and waahm7 committed Aug 5, 2024
1 parent 72e9f47 commit 26be737
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: GitHub Action for SwiftLint
uses: norio-nomura/action-swiftlint@3.2.1

Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
runs-on: ubuntu-22.04 # latest
steps:
- name: Checkout Source
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0
Expand Down
16 changes: 16 additions & 0 deletions Source/AwsCommonRuntimeKit/crt/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,19 @@ func withByteCursorFromStrings<Result>(
}
}
}

extension Array where Element == String {
func withByteCursorArray<R>(_ body: (UnsafePointer<aws_byte_cursor>, Int) -> R) -> R {
let len = self.count
let cStrings = self.map { strdup($0) }
let cursors = cStrings.map { aws_byte_cursor_from_c_str($0) }

defer {
cStrings.forEach { free($0) }
}

return cursors.withUnsafeBufferPointer { cursorsPtr in
return body(cursorsPtr.baseAddress!, len)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ public class EndpointsRequestContext {
}
}

/// Add a string array endpoint parameter to the request context
/// - Parameters:
/// - name: The name of the parameter
/// - value: The value of the parameter
public func add(name: String, value: [String]?) throws {
guard let value = value else {
return
}
if (name.withByteCursor { nameCursor in
value.withByteCursorArray { ptr, len in
aws_endpoints_request_context_add_string_array(allocator.rawValue, rawValue, nameCursor, ptr, len)
}
}) != AWS_OP_SUCCESS {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}

deinit {
aws_endpoints_request_context_release(rawValue)
}
Expand Down
27 changes: 27 additions & 0 deletions Test/AwsCommonRuntimeKitTests/crt/Utilities.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

import XCTest
@testable import AwsCommonRuntimeKit
import AwsCCommon

class UtilitiesTests: XCBaseTestCase {

func testStringArrayToByteCursorArray() {
let strings1 = ["a", "b"]
strings1.withByteCursorArray { cursors, len in
XCTAssertEqual(len, 2)
for i in 0..<len {
withUnsafePointer(to: cursors[i]) { pointer in
XCTAssertTrue(aws_byte_cursor_is_valid(pointer))
}
}
}

let strings2: [String] = []
strings2.withByteCursorArray { cursors, len in
XCTAssertEqual(len, 0)
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EndpointsRuleEngineTests: XCBaseTestCase {
"partitions": [
{
"id": "aws",
"regionRegex": "^(us|eu|ap|sa|ca|me|af)-\\w+-\\d+$",
"regionRegex": "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$",
"regions": {
"af-south-1": {},
"af-east-1": {},
Expand Down Expand Up @@ -282,4 +282,12 @@ class EndpointsRuleEngineTests: XCBaseTestCase {
let _ = try! engine.resolve(context: context)
}
}

func testRequestContext() {
let context = try! EndpointsRequestContext()
try! context.add(name: "Region", value: "us-west-2")
try! context.add(name: "Boolean", value: true)
try! context.add(name: "StringArray", value: ["a", "b"])
try! context.add(name: "StringArray", value: [])
}
}
2 changes: 1 addition & 1 deletion aws-common-runtime/s2n
Submodule s2n updated 83 files
+3 −0 .github/workflows/proof_ci.yaml
+1 −1 CMakeLists.txt
+23 −0 api/s2n.h
+110 −0 api/unstable/fingerprint.h
+1 −5 bindings/rust/integration/Cargo.toml
+0 −26 bindings/rust/integration/benches/handshake.rs
+1 −1 bindings/rust/s2n-tls-sys/templates/Cargo.template
+2 −2 bindings/rust/s2n-tls-tokio/Cargo.toml
+2 −5 bindings/rust/s2n-tls/Cargo.toml
+14 −33 bindings/rust/s2n-tls/src/callbacks/pkey.rs
+5 −270 bindings/rust/s2n-tls/src/client_hello.rs
+15 −0 bindings/rust/s2n-tls/src/connection.rs
+720 −0 bindings/rust/s2n-tls/src/fingerprint.rs
+4 −2 bindings/rust/s2n-tls/src/lib.rs
+7 −215 bindings/rust/s2n-tls/src/testing.rs
+21 −58 bindings/rust/s2n-tls/src/testing/resumption.rs
+63 −242 bindings/rust/s2n-tls/src/testing/s2n_tls.rs
+0 −2 codebuild/bin/criterion_baseline.sh
+0 −2 codebuild/bin/criterion_delta.sh
+0 −7 codebuild/bin/s2n_codebuild.sh
+1 −6 codebuild/bin/s2n_codebuild_al2.sh
+0 −1 codebuild/bin/s2n_setup_env.sh
+1 −8 codebuild/spec/buildspec_generalbatch.yml
+1 −6 codebuild/spec/buildspec_omnibus.yml
+0 −2 codebuild/spec/buildspec_ubuntu_integv2criterion.yml
+100 −104 crypto/s2n_aead_cipher_aes_gcm.c
+38 −38 crypto/s2n_aead_cipher_chacha20_poly1305.c
+15 −15 crypto/s2n_cbc_cipher_3des.c
+25 −25 crypto/s2n_cbc_cipher_aes.c
+5 −5 crypto/s2n_cipher.h
+37 −37 crypto/s2n_composite_cipher_aes_sha.c
+8 −8 crypto/s2n_stream_cipher_null.c
+17 −17 crypto/s2n_stream_cipher_rc4.c
+2 −2 flake.nix
+2 −2 tests/cbmc/proofs/lib/summarize.py
+1 −6 tests/integrationv2/conftest.py
+0 −3 tests/integrationv2/global_flags.py
+0 −1 tests/integrationv2/tox.ini
+ tests/pcap/data/tcp_fragmentation.pcap
+29 −13 tests/pcap/src/handshake_message.rs
+1 −0 tests/pcap/tests/s2n_client_hellos.rs
+1 −0 tests/pems/permutations/generate-certs.sh
+14 −0 tests/pems/permutations/rsae_pkcs_1024_sha1/ca-cert.pem
+14 −0 tests/pems/permutations/rsae_pkcs_1024_sha1/client-cert.pem
+16 −0 tests/pems/permutations/rsae_pkcs_1024_sha1/client-key.pem
+42 −0 tests/pems/permutations/rsae_pkcs_1024_sha1/server-chain.pem
+16 −0 tests/pems/permutations/rsae_pkcs_1024_sha1/server-key.pem
+4 −4 tests/testlib/s2n_connection_test_utils.c
+7 −6 tests/unit/s2n_3des_test.c
+6 −6 tests/unit/s2n_aead_aes_test.c
+12 −12 tests/unit/s2n_aead_chacha20_poly1305_test.c
+8 −8 tests/unit/s2n_aes_sha_composite_test.c
+12 −12 tests/unit/s2n_aes_test.c
+0 −17 tests/unit/s2n_config_test.c
+25 −0 tests/unit/s2n_connection_test.c
+7 −7 tests/unit/s2n_fingerprint_ja3_test.c
+716 −0 tests/unit/s2n_fingerprint_test.c
+4 −4 tests/unit/s2n_handshake_io_early_data_test.c
+8 −8 tests/unit/s2n_rc4_test.c
+21 −21 tests/unit/s2n_record_size_test.c
+26 −0 tests/unit/s2n_resume_test.c
+56 −0 tests/unit/s2n_security_policy_cert_preferences_test.c
+6 −6 tests/unit/s2n_send_key_update_test.c
+226 −0 tests/unit/s2n_session_ticket_test.c
+10 −10 tests/unit/s2n_tls13_key_schedule_rfc8448_test.c
+12 −0 tests/unit/s2n_tls13_pq_handshake_test.c
+11 −11 tests/unit/s2n_tls13_record_aead_test.c
+4 −2 tls/extensions/s2n_client_session_ticket.c
+2 −1 tls/extensions/s2n_server_session_ticket.c
+20 −0 tls/s2n_config.c
+2 −0 tls/s2n_config.h
+9 −6 tls/s2n_connection.c
+2 −2 tls/s2n_crypto.c
+194 −243 tls/s2n_fingerprint.c
+58 −0 tls/s2n_fingerprint.h
+227 −0 tls/s2n_fingerprint_ja3.c
+6 −6 tls/s2n_prf.c
+13 −12 tls/s2n_resume.c
+2 −0 tls/s2n_security_policies.c
+2 −2 tls/s2n_tls13_handshake.c
+2 −2 tls/s2n_tls13_key_schedule.c
+3 −1 tls/s2n_x509_validator.c
+1 −1 utils/s2n_safety.h

0 comments on commit 26be737

Please sign in to comment.