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
Next Next commit
Use #if canImport(Darwin) where possible
  • Loading branch information
FranzBusch committed Jun 22, 2023
commit 141d3f1e3548ec744680c6e16dd6788ad868d3c4
2 changes: 1 addition & 1 deletion Sources/NIOSSH/CSPRNG/CSPRNG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct CSPRNG: RandomNumberGenerator {
private var baseRNG: SystemRandomNumberGenerator

init() {
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(Linux) || os(Android)
#if canImport(Darwin) || os(Linux) || os(Android)
self.baseRNG = SystemRandomNumberGenerator()
#else
fatalError("Platform does not have a supported CSPRNG")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
import Crypto
import Dispatch
import NIOCore
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
import Darwin
#else
import Glibc
#endif // os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#endif // canImport(Darwin)

/// A ``NIOSSHCertifiedPublicKey`` is an SSH public key combined with an SSH certificate.
///
Expand Down
12 changes: 6 additions & 6 deletions Sources/NIOSSH/Keys And Signatures/NIOSSHPrivateKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct NIOSSHPrivateKey {
self.backingKey = .ecdsaP521(key)
}

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
public init(secureEnclaveP256Key key: SecureEnclave.P256.Signing.PrivateKey) {
self.backingKey = .secureEnclaveP256(key)
}
Expand All @@ -63,7 +63,7 @@ public struct NIOSSHPrivateKey {
return ["ecdsa-sha2-nistp384"]
case .ecdsaP521:
return ["ecdsa-sha2-nistp521"]
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
case .secureEnclaveP256:
return ["ecdsa-sha2-nistp256"]
#endif
Expand All @@ -79,7 +79,7 @@ extension NIOSSHPrivateKey {
case ecdsaP384(P384.Signing.PrivateKey)
case ecdsaP521(P521.Signing.PrivateKey)

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
case secureEnclaveP256(SecureEnclave.P256.Signing.PrivateKey)
#endif
}
Expand Down Expand Up @@ -109,7 +109,7 @@ extension NIOSSHPrivateKey {
}
return NIOSSHSignature(backingSignature: .ecdsaP521(signature))

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
case .secureEnclaveP256(let key):
let signature = try digest.withUnsafeBytes { ptr in
try key.signature(for: ptr)
Expand All @@ -133,7 +133,7 @@ extension NIOSSHPrivateKey {
case .ecdsaP521(let key):
let signature = try key.signature(for: payload.bytes.readableBytesView)
return NIOSSHSignature(backingSignature: .ecdsaP521(signature))
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
case .secureEnclaveP256(let key):
let signature = try key.signature(for: payload.bytes.readableBytesView)
return NIOSSHSignature(backingSignature: .ecdsaP256(signature))
Expand All @@ -154,7 +154,7 @@ extension NIOSSHPrivateKey {
return NIOSSHPublicKey(backingKey: .ecdsaP384(privateKey.publicKey))
case .ecdsaP521(let privateKey):
return NIOSSHPublicKey(backingKey: .ecdsaP521(privateKey.publicKey))
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
case .secureEnclaveP256(let privateKey):
return NIOSSHPublicKey(backingKey: .ecdsaP256(privateKey.publicKey))
#endif
Expand Down
2 changes: 1 addition & 1 deletion Tests/NIOSSHTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ class EndToEndTests: XCTestCase {
func testSecureEnclaveKeys() throws {
// This is a quick end-to-end test that validates that we support secure enclave private keys
// on appropriate platforms.
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
#if canImport(Darwin)
// If we can't create this key, we skip the test.
let key: NIOSSHPrivateKey
do {
Expand Down