Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Sources/NIOSSHServer/DataToBufferCodec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)

import Dispatch
import Foundation
import NIOCore
Expand Down Expand Up @@ -57,3 +59,5 @@ func createOutboundConnection(targetHost: String, targetPort: Int, loop: EventLo
channel.eventLoop.makeSucceededFuture(())
}.connect(host: targetHost, port: targetPort)
}

#endif // canImport(Foundation.Process)
4 changes: 4 additions & 0 deletions Sources/NIOSSHServer/ExecHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL that you can import check types and not only modules.

With that being said, why don't we use @available instead like we do in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because that doesn't stop it trying to compile the code. If Foundation.Process was present on e.g. iOS but not available, then we could use @available here too, but it is simply not present in the iOS SDK (and others), so we must use a compiler directive.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thanks


import Dispatch
import Foundation
import NIOCore
Expand Down Expand Up @@ -156,3 +158,5 @@ final class ExampleExecHandler: ChannelDuplexHandler {
}
}
}

#endif // canImport(Foundation.Process)
4 changes: 4 additions & 0 deletions Sources/NIOSSHServer/GlueHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)

import NIOCore

final class GlueHandler {
Expand Down Expand Up @@ -122,3 +124,5 @@ extension GlueHandler: ChannelDuplexHandler {
}
}
}

#endif // canImport(Foundation.Process)
4 changes: 4 additions & 0 deletions Sources/NIOSSHServer/RemotePortForwarding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)

import Dispatch
import Foundation
import NIOCore
Expand Down Expand Up @@ -97,3 +99,5 @@ final class RemotePortForwarderGlobalRequestDelegate: GlobalRequestDelegate {
self.forwarder?.stopListening()
}
}

#endif // canImport(Foundation.Process)
8 changes: 8 additions & 0 deletions Sources/NIOSSHServer/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
//
//===----------------------------------------------------------------------===//

#if canImport(Foundation.Process)

import Crypto
import Dispatch
import NIOCore
Expand Down Expand Up @@ -85,3 +87,9 @@ let channel = try bootstrap.bind(host: "0.0.0.0", port: 2222).wait()

// Run forever
try channel.closeFuture.wait()

#else // canImport(Foundation.Process)

fatalError("NIOSSHServer is only supported on platforms with Foundation.Process")

#endif // !canImport(Foundation.Process)
1 change: 1 addition & 0 deletions Tests/NIOSSHTests/SSHConnectionStateMachineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ final class SSHConnectionStateMachineTests: XCTestCase {
}
}

@available(iOS 13.2, macOS 10.15, watchOS 6.1, tvOS 13.2, *)
func testFirstBlockDecodedOnce() throws {
let allocator = ByteBufferAllocator()
let loop = EmbeddedEventLoop()
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOSSHTests/SSHPackerSerializerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ final class SSHPacketSerializerTests: XCTestCase {
}
}

@available(iOS 13.2, macOS 10.15, watchOS 6.1, tvOS 13.2, *)
func testSequencePreservedBetweenPlainAndCypher() {
let message = SSHMessage.newKeys
let allocator = ByteBufferAllocator()
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOSSHTests/SSHPacketParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ final class SSHPacketParserTests: XCTestCase {
XCTAssertEqual(parser._discardableBytes, 0)
}

@available(iOS 13.2, macOS 10.15, watchOS 6.1, tvOS 13.2, *)
func testSequencePreservedBetweenPlainAndCypher() throws {
let allocator = ByteBufferAllocator()
var parser = SSHPacketParser(isServer: false, allocator: allocator)
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOSSHTests/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ struct InsecureEncryptionAlgorithm {
}
}

@available(iOS 13.2, macOS 10.15, watchOS 6.1, tvOS 13.2, *)
class TestTransportProtection: NIOSSHTransportProtection {
enum TestError: Error {
case doubleDecode
Expand Down
1 change: 1 addition & 0 deletions Tests/NIOSSHTests/UtilitiesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final class UtilitiesTests: XCTestCase {
XCTAssertEqual(message, plaintext)
}

@available(iOS 13.2, macOS 10.15, watchOS 6.1, tvOS 13.2, *)
func testTestTransportProtection() throws {
let inboundEncryptionKey = SymmetricKey(size: .bits128)
let outboundEncryptionKey = SymmetricKey(size: .bits128)
Expand Down