Skip to content

Commit dcc089f

Browse files
FranzBuschLukasa
andauthored
Use #if canImport(Darwin) where possible (#148)
Co-authored-by: Cory Benfield <[email protected]>
1 parent 64a14c0 commit dcc089f

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

Sources/NIOSSH/CSPRNG/CSPRNG.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct CSPRNG: RandomNumberGenerator {
3131
private var baseRNG: SystemRandomNumberGenerator
3232

3333
init() {
34-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux) || os(Android)
34+
#if canImport(Darwin) || os(Linux) || os(Android)
3535
self.baseRNG = SystemRandomNumberGenerator()
3636
#else
3737
fatalError("Platform does not have a supported CSPRNG")

Sources/NIOSSH/Keys And Signatures/NIOSSHCertifiedPublicKey.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
import Crypto
1616
import Dispatch
1717
import NIOCore
18-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
18+
#if canImport(Darwin)
1919
import Darwin
2020
#else
2121
import Glibc
22-
#endif // os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
22+
#endif // canImport(Darwin)
2323

2424
/// A ``NIOSSHCertifiedPublicKey`` is an SSH public key combined with an SSH certificate.
2525
///

Sources/NIOSSH/Keys And Signatures/NIOSSHPrivateKey.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public struct NIOSSHPrivateKey {
4646
self.backingKey = .ecdsaP521(key)
4747
}
4848

49-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
49+
#if canImport(Darwin)
5050
public init(secureEnclaveP256Key key: SecureEnclave.P256.Signing.PrivateKey) {
5151
self.backingKey = .secureEnclaveP256(key)
5252
}
@@ -63,7 +63,7 @@ public struct NIOSSHPrivateKey {
6363
return ["ecdsa-sha2-nistp384"]
6464
case .ecdsaP521:
6565
return ["ecdsa-sha2-nistp521"]
66-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
66+
#if canImport(Darwin)
6767
case .secureEnclaveP256:
6868
return ["ecdsa-sha2-nistp256"]
6969
#endif
@@ -79,7 +79,7 @@ extension NIOSSHPrivateKey {
7979
case ecdsaP384(P384.Signing.PrivateKey)
8080
case ecdsaP521(P521.Signing.PrivateKey)
8181

82-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
82+
#if canImport(Darwin)
8383
case secureEnclaveP256(SecureEnclave.P256.Signing.PrivateKey)
8484
#endif
8585
}
@@ -109,7 +109,7 @@ extension NIOSSHPrivateKey {
109109
}
110110
return NIOSSHSignature(backingSignature: .ecdsaP521(signature))
111111

112-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
112+
#if canImport(Darwin)
113113
case .secureEnclaveP256(let key):
114114
let signature = try digest.withUnsafeBytes { ptr in
115115
try key.signature(for: ptr)
@@ -133,7 +133,7 @@ extension NIOSSHPrivateKey {
133133
case .ecdsaP521(let key):
134134
let signature = try key.signature(for: payload.bytes.readableBytesView)
135135
return NIOSSHSignature(backingSignature: .ecdsaP521(signature))
136-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
136+
#if canImport(Darwin)
137137
case .secureEnclaveP256(let key):
138138
let signature = try key.signature(for: payload.bytes.readableBytesView)
139139
return NIOSSHSignature(backingSignature: .ecdsaP256(signature))
@@ -154,7 +154,7 @@ extension NIOSSHPrivateKey {
154154
return NIOSSHPublicKey(backingKey: .ecdsaP384(privateKey.publicKey))
155155
case .ecdsaP521(let privateKey):
156156
return NIOSSHPublicKey(backingKey: .ecdsaP521(privateKey.publicKey))
157-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
157+
#if canImport(Darwin)
158158
case .secureEnclaveP256(let privateKey):
159159
return NIOSSHPublicKey(backingKey: .ecdsaP256(privateKey.publicKey))
160160
#endif

Tests/NIOSSHTests/EndToEndTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ class EndToEndTests: XCTestCase {
411411
func testSecureEnclaveKeys() throws {
412412
// This is a quick end-to-end test that validates that we support secure enclave private keys
413413
// on appropriate platforms.
414-
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
414+
#if canImport(Darwin)
415415
// If we can't create this key, we skip the test.
416416
let key: NIOSSHPrivateKey
417417
do {

0 commit comments

Comments
 (0)