|
16 | 16 |
|
17 | 17 | import Foundation
|
18 | 18 | import Network
|
| 19 | + import NIO |
19 | 20 | import NIOSSL
|
20 | 21 | import NIOTransportServices
|
21 | 22 |
|
|
58 | 59 |
|
59 | 60 | /// create NWProtocolTLS.Options for use with NIOTransportServices from the NIOSSL TLSConfiguration
|
60 | 61 | ///
|
61 |
| - /// - Parameter queue: Dispatch queue to run `sec_protocol_options_set_verify_block` on. |
| 62 | + /// - Parameter eventLoop: EventLoop to wait for creation of options on |
| 63 | + /// - Returns: Future holding NWProtocolTLS Options |
| 64 | + func getNWProtocolTLSOptions(on eventLoop: EventLoop) -> EventLoopFuture<NWProtocolTLS.Options> { |
| 65 | + let promise = eventLoop.makePromise(of: NWProtocolTLS.Options.self) |
| 66 | + Self.tlsDispatchQueue.async { |
| 67 | + do { |
| 68 | + let options = try self.getNWProtocolTLSOptions() |
| 69 | + promise.succeed(options) |
| 70 | + } catch { |
| 71 | + promise.fail(error) |
| 72 | + } |
| 73 | + } |
| 74 | + return promise.futureResult |
| 75 | + } |
| 76 | + |
| 77 | + /// create NWProtocolTLS.Options for use with NIOTransportServices from the NIOSSL TLSConfiguration |
| 78 | + /// |
62 | 79 | /// - Returns: Equivalent NWProtocolTLS Options
|
63 | 80 | func getNWProtocolTLSOptions() throws -> NWProtocolTLS.Options {
|
64 | 81 | let options = NWProtocolTLS.Options()
|
|
138 | 155 | break
|
139 | 156 | }
|
140 | 157 |
|
141 |
| - precondition(self.certificateVerification != .noHostnameVerification, "TLSConfiguration.certificateVerification = .noHostnameVerification is not supported") |
| 158 | + precondition(self.certificateVerification != .noHostnameVerification, |
| 159 | + "TLSConfiguration.certificateVerification = .noHostnameVerification is not supported. \(useMTELGExplainer)") |
142 | 160 |
|
143 | 161 | if certificateVerification != .fullVerification || trustRoots != nil {
|
144 | 162 | // add verify block to control certificate verification
|
|
173 | 191 | }
|
174 | 192 | }, Self.tlsDispatchQueue
|
175 | 193 | )
|
176 |
| - |
177 |
| - case .noHostnameVerification: |
178 |
| - precondition(self.certificateVerification != .noHostnameVerification, |
179 |
| - "TLSConfiguration.certificateVerification = .noHostnameVerification is not supported. \(useMTELGExplainer)") |
180 |
| - |
181 |
| - case .fullVerification: |
182 |
| - break |
183 | 194 | }
|
184 | 195 | return options
|
185 | 196 | }
|
|
0 commit comments