Skip to content

Commit

Permalink
first pass
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Aug 2, 2024
1 parent 72e9f47 commit b0dbb64
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 9 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
37 changes: 37 additions & 0 deletions Source/AwsCommonRuntimeKit/crt/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,40 @@ func withByteCursorFromStrings<Result>(
}
}
}

public func scan<
S : Sequence, U

Check failure on line 277 in Source/AwsCommonRuntimeKit/crt/Utilities.swift

View workflow job for this annotation

GitHub Actions / lint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
>(_ seq: S, _ initial: U, _ combine: (U, S.Element) -> U) -> [U] {
var result: [U] = []
result.reserveCapacity(seq.underestimatedCount)
var runningResult = initial
for element in seq {
runningResult = combine(runningResult, element)
result.append(runningResult)
}
return result
}

/// Note: this function and associated scan function above are copied verbatim from
/// swift standard lib where its private.
public func withArrayOfCStrings<R>(
_ args: [String], _ body: ([UnsafeMutablePointer<CChar>?]) -> R
) -> R {
let argsCounts = Array(args.map { $0.utf8.count + 1 })
let argsOffsets = [ 0 ] + scan(argsCounts, 0, +)
let argsBufferSize = argsOffsets.last!
var argsBuffer: [UInt8] = []
argsBuffer.reserveCapacity(argsBufferSize)
for arg in args {
argsBuffer.append(contentsOf: arg.utf8)
argsBuffer.append(0)
}
return argsBuffer.withUnsafeMutableBufferPointer {
(argsBuffer) in

Check warning on line 304 in Source/AwsCommonRuntimeKit/crt/Utilities.swift

View workflow job for this annotation

GitHub Actions / lint

Closure Parameter Position Violation: Closure parameters should be on the same line as opening brace (closure_parameter_position)
let ptr = UnsafeMutableRawPointer(argsBuffer.baseAddress!).bindMemory(
to: CChar.self, capacity: argsBuffer.count)
var cStrings: [UnsafeMutablePointer<CChar>?] = argsOffsets.map { ptr + $0 }
cStrings[cStrings.count - 1] = nil
return body(cStrings)
}
}

Check warning on line 311 in Source/AwsCommonRuntimeKit/crt/Utilities.swift

View workflow job for this annotation

GitHub Actions / lint

Trailing Newline Violation: Files should have a single trailing newline (trailing_newline)
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,34 @@ public class EndpointsRequestContext {
}
}

private func withByteCursorArrayFromStringArray<R>(_ arg: [String],
_ body: (UnsafeMutablePointer<aws_byte_cursor>, Int) -> R) -> R {

Check failure on line 52 in Source/AwsCommonRuntimeKit/sdkutils/endpoint/EndpointsRequestContext.swift

View workflow job for this annotation

GitHub Actions / lint

Vertical Parameter Alignment Violation: Function parameters should be aligned vertically if they're in multiple lines in a declaration (vertical_parameter_alignment)
withArrayOfCStrings(arg) { cStrArr in
var cursors = cStrArr.map { aws_byte_cursor_from_c_str($0) }
let len = cursors.count
return cursors.withUnsafeMutableBufferPointer { cursorsPtr in
return body(cursorsPtr.baseAddress!, len)
}
}
}

/// 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
withByteCursorArrayFromStringArray(value) { 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
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,11 @@ 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"])
}
}
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-common
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 b0dbb64

Please sign in to comment.