refactor: move request signing to Swift - #872
nickolas-dimitrakas merged 1 commit into
Conversation
🐦 Swift Migration ProgressProduction implementation code at
Objective-C retained by design: Core SDK 5,855 · SDK kit infrastructure 385 · Standalone kits 0. This PR's code movement
How this is measured
Generated with |
📦 SDK Size Impact ReportMeasures how much the SDK adds to an app's size (with-SDK minus without-SDK).
➡️ SDK size impact change is minimal. Raw measurementsTarget branch (workstation/swift-migration): {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2292,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2208,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6824}This PR: {"baseline_app_size_kb":84,"baseline_executable_size_bytes":75464,"with_sdk_app_size_kb":2296,"with_sdk_executable_size_bytes":76312,"sdk_impact_kb":2212,"sdk_executable_impact_bytes":848,"xcframework_size_kb":6828} |
1832cb7 to
4ebab21
Compare
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit 0e50c4c. Bugbot is set up for automated code reviews on this repo. Configure here. |
Extracts HMAC-SHA256 encoding and signature-message assembly from MPURLRequestBuilder into a Foundation-only Swift type, per docs/swift-migration/CONVERSION-RECIPE.md. MPRequestSigner owns four things: the HMAC hex encode, the two signature-message shapes (path + "?" + query for config and audience, path + body for identity and events), and the 8192-character query cap. The .m still owns NSMutableURLRequest, the cache policy, the timeout, every header assignment, and its MPILogError calls -- it resolves the state machine, kit container, web view and user defaults into plain values before calling Swift, because mParticle-Apple-SDK-Swift cannot import the ObjC module. hmacSha256Encode:key: keeps its selector as a one-line forward. MPURLRequestBuilderTests.m calls it through a test-only category, and it stays the behaviour contract. Two ObjC behaviours are preserved deliberately and covered by tests: - The original passed the strings through cStringUsingEncoding: and strlen, so an embedded NUL truncates the message or the key. Swift reproduces that by hashing only the bytes before the first NUL. - A nil message or key yields nil, but an empty message still hashes. MPURLRequestBuilderTests testInvalidHMACSha256Encode pins both. The query cap counts UTF-16 units, matching NSString.length rather than Swift's grapheme count. Signing switches from CommonCrypto to CryptoKit. Both are system libraries, so no podspec or Package.swift change is needed, and the output is byte-identical -- verified against the existing ObjC reference vector plus a new openssl-derived one in the Swift mirror test. MPURLRequestBuilder is not in mParticle-Apple-SDK/Include/, so it has no ABI baseline entry; Include/ has a zero diff and abi-guard.sh check passes. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4ebab21 to
0e50c4c
Compare
95f8700
into
workstation/swift-migration
The stack
Review bottom-up; merge top-down. This is #872.
First of five. Stacked on #868 — base it on #868's head after that PR is rebased onto
workstation/swift-migration; it currently branches off #861 and is missing #862.What moves
MPRequestSignerowns four things extracted fromMPURLRequestBuilder:METHOD\nDATE\npath[?query]signature shape (config, audience),METHOD\nDATE\npath<body>shape (identity, events),hmacSha256Encode:key:keeps its selector as a one-line forward.MPURLRequestBuilderTests.mcalls it through a test-only category and remains thebehaviour contract.
Two ObjC quirks preserved on purpose
cStringUsingEncoding:+strlen, so anything after a NUL was never hashed. Swiftreproduces that by hashing only the bytes before the first NUL —
bytesUpToFirstNUL.testInvalidHMACSha256Encodepins both halves.The query cap counts UTF-16 units to match
NSString.length, not Swift's grapheme count.CommonCrypto → CryptoKit
Both are system libraries, so no podspec or
Package.swiftchange. Output isbyte-identical, verified against the existing ObjC reference vector plus a new
openssl-derived one in the Swift mirror test.
Gate
abi-guard.sh checkclean,Include/diff emptypod lib lintx3 podspecstrunk checkMPURLRequestBuilderis not inmParticle-Apple-SDK/Include/, so it has no ABI baselineentry.
tvOS is CI-only: this machine has the tvOS 26.2 SDK but only the 26.0 simulator
runtime, so no tvOS destination resolves and pod lint's tvOS leg fails the whole lint even
though iOS passes. Environmental, not a compile failure.
On the test suites: both suites flake under Xcode's default parallel testing on this
machine —
MPUserDefaultsTestsraces on sharedUserDefaults, and several slow ObjCtests time out and force an xctest restart that prints "0 failures" while silently
skipping ~75 tests. Both reproduce on the unmodified base, so the counts above were taken
with
-parallel-testing-enabled NO. Filed separately.🤖 Generated with Claude Code