Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
move call to background thread
  • Loading branch information
bparrishMines committed Apr 6, 2025
commit 364dbcfa82bad6a47629dc101eca2fbe3519d22c
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,20 @@ import Foundation
/// This class may handle instantiating native object instances that are attached to a Dart instance
/// or handle method calls on the associated native class or an instance of that class.
class SecTrustProxyAPIDelegate : PigeonApiDelegateSecTrust {
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper) throws -> Bool {
var error: CFError?
let result = secTrustEvaluateWithError(trust.value, &error)
if let error = error {
throw PigeonError(code: CFErrorGetDomain(error) as String, message: CFErrorCopyDescription(error) as String, details: nil)
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper, completion: @escaping (Result<Bool, any Error>) -> Void) {
/// `SecTrustEvaluateWithError` should not be called on main thread, so this calls the method on a background thread.
DispatchQueue.global().async {
var error: CFError?
let result = self.secTrustEvaluateWithError(trust.value, &error)

DispatchQueue.main.async {
if let error = error {
completion(Result.failure(PigeonError(code: CFErrorGetDomain(error) as String, message: CFErrorCopyDescription(error) as String, details: nil)))
} else {
completion(Result.success(result))
}
}
}
return result
}

func copyExceptions(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper) throws -> FlutterStandardTypedData? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9735,7 +9735,7 @@ class GetTrustResultResponseProxyAPITests: XCTestCase {

protocol PigeonApiDelegateSecTrust {
/// Evaluates trust for the specified certificate and policies.
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper) throws -> Bool
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper, completion: @escaping (Result<Bool, Error>) -> Void)
/// Returns an opaque cookie containing exceptions to trust policies that will
/// allow future evaluations of the current certificate to succeed.
func copyExceptions(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper) throws -> FlutterStandardTypedData?
Expand Down Expand Up @@ -9774,11 +9774,13 @@ final class PigeonApiSecTrust: PigeonApiProtocolSecTrust {
evaluateWithErrorChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let trustArg = args[0] as! SecTrustWrapper
do {
let result = try api.pigeonDelegate.evaluateWithError(pigeonApi: api, trust: trustArg)
reply(wrapResult(result))
} catch {
reply(wrapError(error))
api.pigeonDelegate.evaluateWithError(pigeonApi: api, trust: trustArg) { result in
switch result {
case .success(let res):
reply(wrapResult(res))
case .failure(let error):
reply(wrapError(error))
}
}
}
} else {
Expand Down Expand Up @@ -9895,7 +9897,7 @@ import Foundation
/// This class may handle instantiating native object instances that are attached to a Dart instance
/// or handle method calls on the associated native class or an instance of that class.
class SecTrustProxyAPIDelegate : PigeonApiDelegateSecTrust {
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper) throws -> Bool {
func evaluateWithError(pigeonApi: PigeonApiSecTrust, trust: SecTrustWrapper, completion: @escaping (Result<Bool, PigeonError>) -> Void) {
return SecTrust.evaluateWithError(trust: trust)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,22 @@ class SecTrustProxyAPITests: XCTestCase {
let delegate = TestSecTrustProxyAPIDelegate()
let api = PigeonApiSecTrust(pigeonRegistrar: registrar, delegate: delegate)

let expect = expectation(description: "Wait for setCookie.")
let trust = createTrust(delegate: delegate)
let value = try? api.pigeonDelegate.evaluateWithError(pigeonApi: api, trust: trust)
var resultValue: Bool?

api.pigeonDelegate.evaluateWithError(pigeonApi: api, trust: trust) { result in
switch result {
case .success(let value):
resultValue = value
case .failure(_):
break
}
expect.fulfill()
}

XCTAssertEqual(value, true)
wait(for: [expect], timeout: 5.0)
XCTAssertEqual(resultValue, true)
}

func testCopyExceptions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,7 @@ abstract class GetTrustResultResponse extends NSObject {
abstract class SecTrust extends NSObject {
/// Evaluates trust for the specified certificate and policies.
@static
@async
bool evaluateWithError(SecTrust trust);

/// Returns an opaque cookie containing exceptions to trust policies that will
Expand Down