diff --git a/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ClientTransport+Posix.swift b/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ClientTransport+Posix.swift index 1e3e22d..8740097 100644 --- a/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ClientTransport+Posix.swift +++ b/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ClientTransport+Posix.swift @@ -18,10 +18,7 @@ public import GRPCCore public import GRPCNIOTransportCore // should be @usableFromInline public import NIOCore // has to be public because of EventLoopGroup param in init public import NIOPosix // has to be public because of default argument value in init - -#if canImport(NIOSSL) private import NIOSSL -#endif extension HTTP2ClientTransport { /// A `ClientTransport` using HTTP/2 built on top of `NIOPosix`. @@ -129,23 +126,20 @@ extension HTTP2ClientTransport.Posix { private let config: HTTP2ClientTransport.Posix.Config private let eventLoopGroup: any EventLoopGroup - #if canImport(NIOSSL) - private let nioSSLContext: NIOSSLContext? + private let sslContext: NIOSSLContext? private let serverHostname: String? - #endif init(eventLoopGroup: any EventLoopGroup, config: HTTP2ClientTransport.Posix.Config) throws { self.eventLoopGroup = eventLoopGroup self.config = config - #if canImport(NIOSSL) switch self.config.transportSecurity.wrapped { case .plaintext: - self.nioSSLContext = nil + self.sslContext = nil self.serverHostname = nil case .tls(let tlsConfig): do { - self.nioSSLContext = try NIOSSLContext(configuration: TLSConfiguration(tlsConfig)) + self.sslContext = try NIOSSLContext(configuration: TLSConfiguration(tlsConfig)) self.serverHostname = tlsConfig.serverHostname } catch { throw RuntimeError( @@ -155,7 +149,6 @@ extension HTTP2ClientTransport.Posix { ) } } - #endif } func establishConnection( @@ -165,16 +158,14 @@ extension HTTP2ClientTransport.Posix { group: self.eventLoopGroup ).connect(to: address) { channel in channel.eventLoop.makeCompletedFuture { - #if canImport(NIOSSL) - if let nioSSLContext = self.nioSSLContext { + if let sslContext = self.sslContext { try channel.pipeline.syncOperations.addHandler( NIOSSLClientHandler( - context: nioSSLContext, + context: sslContext, serverHostname: self.serverHostname ) ) } - #endif return try channel.pipeline.syncOperations.configureGRPCClientPipeline( channel: channel, diff --git a/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ServerTransport+Posix.swift b/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ServerTransport+Posix.swift index 1c19c2c..e397eca 100644 --- a/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ServerTransport+Posix.swift +++ b/Sources/GRPCNIOTransportHTTP2Posix/HTTP2ServerTransport+Posix.swift @@ -20,12 +20,9 @@ internal import NIOCore internal import NIOExtras internal import NIOHTTP2 public import NIOPosix // has to be public because of default argument value in init +private import NIOSSL private import Synchronization -#if canImport(NIOSSL) -import NIOSSL -#endif - extension HTTP2ServerTransport { /// A `ServerTransport` using HTTP/2 built on top of `NIOPosix`. /// @@ -63,7 +60,6 @@ extension HTTP2ServerTransport { address: GRPCNIOTransportCore.SocketAddress, serverQuiescingHelper: ServerQuiescingHelper ) async throws -> NIOAsyncChannel { - #if canImport(NIOSSL) let sslContext: NIOSSLContext? switch self.config.transportSecurity.wrapped { @@ -80,7 +76,6 @@ extension HTTP2ServerTransport { ) } } - #endif let serverChannel = try await ServerBootstrap(group: eventLoopGroup) .serverChannelOption(.socketOption(.so_reuseaddr), value: 1) @@ -90,13 +85,11 @@ extension HTTP2ServerTransport { } .bind(to: address) { channel in channel.eventLoop.makeCompletedFuture { - #if canImport(NIOSSL) if let sslContext { try channel.pipeline.syncOperations.addHandler( NIOSSLServerHandler(context: sslContext) ) } - #endif let requireALPN: Bool let scheme: Scheme diff --git a/Sources/GRPCNIOTransportHTTP2Posix/NIOSSL+GRPC.swift b/Sources/GRPCNIOTransportHTTP2Posix/NIOSSL+GRPC.swift index 91487a8..3bc8cf0 100644 --- a/Sources/GRPCNIOTransportHTTP2Posix/NIOSSL+GRPC.swift +++ b/Sources/GRPCNIOTransportHTTP2Posix/NIOSSL+GRPC.swift @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#if canImport(NIOSSL) + import NIOSSL extension NIOSSLSerializationFormats { @@ -159,4 +159,3 @@ extension TLSConfiguration { self.applicationProtocols = ["grpc-exp", "h2"] } } -#endif diff --git a/Sources/GRPCNIOTransportHTTP2Posix/TLSConfig.swift b/Sources/GRPCNIOTransportHTTP2Posix/TLSConfig.swift index 1cbf291..c999b80 100644 --- a/Sources/GRPCNIOTransportHTTP2Posix/TLSConfig.swift +++ b/Sources/GRPCNIOTransportHTTP2Posix/TLSConfig.swift @@ -146,12 +146,10 @@ extension HTTP2ServerTransport.Posix.Config { /// This connection is plaintext: no encryption will take place. public static let plaintext = Self(wrapped: .plaintext) - #if canImport(NIOSSL) /// This connection will use TLS. public static func tls(_ tls: TLS) -> Self { Self(wrapped: .tls(tls)) } - #endif } public struct TLS: Sendable { @@ -261,12 +259,10 @@ extension HTTP2ClientTransport.Posix.Config { /// This connection is plaintext: no encryption will take place. public static let plaintext = Self(wrapped: .plaintext) - #if canImport(NIOSSL) /// This connection will use TLS. public static func tls(_ tls: TLS) -> Self { Self(wrapped: .tls(tls)) } - #endif } public struct TLS: Sendable { diff --git a/Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportNIOPosixTests.swift b/Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportNIOPosixTests.swift index 79e1439..4270446 100644 --- a/Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportNIOPosixTests.swift +++ b/Tests/GRPCNIOTransportHTTP2Tests/HTTP2TransportNIOPosixTests.swift @@ -17,11 +17,8 @@ import GRPCCore import GRPCNIOTransportCore import GRPCNIOTransportHTTP2Posix -import XCTest - -#if canImport(NIOSSL) import NIOSSL -#endif +import XCTest final class HTTP2TransportNIOPosixTests: XCTestCase { func testGetListeningAddress_IPv4() async throws { @@ -191,7 +188,6 @@ final class HTTP2TransportNIOPosixTests: XCTestCase { XCTAssertEqual(grpcConfig.backoff, HTTP2ClientTransport.Config.Backoff.defaults) } - #if canImport(NIOSSL) static let samplePemCert = """ -----BEGIN CERTIFICATE----- MIIGGzCCBAOgAwIBAgIJAJ/X0Fo0ynmEMA0GCSqGSIb3DQEBCwUAMIGjMQswCQYD @@ -478,5 +474,4 @@ final class HTTP2TransportNIOPosixTests: XCTestCase { XCTAssertEqual(nioSSLTLSConfig.trustRoots, .default) XCTAssertEqual(nioSSLTLSConfig.applicationProtocols, ["grpc-exp", "h2"]) } - #endif }