Browse Source

Embrace #if canImport(Darwin)

Marcin Krzyżanowski 7 years ago
parent
commit
9708e093c8

+ 3 - 3
Sources/CryptoSwift/Cryptors.swift

@@ -13,10 +13,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 /// Worker cryptor/decryptor of `Updatable` types
 /// Worker cryptor/decryptor of `Updatable` types

+ 3 - 3
Sources/CryptoSwift/HKDF.swift

@@ -16,10 +16,10 @@
 //  https://www.ietf.org/rfc/rfc5869.txt
 //  https://www.ietf.org/rfc/rfc5869.txt
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 /// A key derivation function.
 /// A key derivation function.

+ 3 - 3
Sources/CryptoSwift/Int+Extension.swift

@@ -14,10 +14,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 /* array of bits */
 /* array of bits */

+ 3 - 3
Sources/CryptoSwift/PKCS/PBKDF2.swift

@@ -16,10 +16,10 @@
 //  https://www.ietf.org/rfc/rfc2898.txt
 //  https://www.ietf.org/rfc/rfc2898.txt
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 public extension PKCS5 {
 public extension PKCS5 {

+ 6 - 6
Sources/CryptoSwift/RandomBytesSequence.swift

@@ -13,10 +13,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
-#else
+#if canImport(Darwin)
     import Darwin
     import Darwin
+#else
+    import Glibc
 #endif
 #endif
 
 
 struct RandomBytesSequence: Sequence {
 struct RandomBytesSequence: Sequence {
@@ -24,8 +24,8 @@ struct RandomBytesSequence: Sequence {
 
 
     func makeIterator() -> AnyIterator<UInt8> {
     func makeIterator() -> AnyIterator<UInt8> {
         var count = 0
         var count = 0
-        return AnyIterator<UInt8>.init({ () -> UInt8? in
-            if count >= self.size {
+        return AnyIterator<UInt8>.init { () -> UInt8? in
+            guard count < self.size else {
                 return nil
                 return nil
             }
             }
             count = count + 1
             count = count + 1
@@ -45,6 +45,6 @@ struct RandomBytesSequence: Sequence {
             #else
             #else
                 return UInt8(arc4random_uniform(UInt32(UInt8.max) + 1))
                 return UInt8(arc4random_uniform(UInt32(UInt8.max) + 1))
             #endif
             #endif
-        })
+        }
     }
     }
 }
 }

+ 3 - 3
Sources/CryptoSwift/SHA3.swift

@@ -17,10 +17,10 @@
 //  http://keccak.noekeon.org/specs_summary.html
 //  http://keccak.noekeon.org/specs_summary.html
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 public final class SHA3: DigestType {
 public final class SHA3: DigestType {

+ 3 - 3
Sources/CryptoSwift/SecureBytes.swift

@@ -13,10 +13,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 typealias Key = SecureBytes
 typealias Key = SecureBytes

+ 3 - 3
Sources/CryptoSwift/UInt32+Extension.swift

@@ -13,10 +13,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 protocol _UInt32Type {}
 protocol _UInt32Type {}

+ 3 - 3
Sources/CryptoSwift/UInt8+Extension.swift

@@ -13,10 +13,10 @@
 //  - This notice may not be removed or altered from any source or binary distribution.
 //  - This notice may not be removed or altered from any source or binary distribution.
 //
 //
 
 
-#if os(Linux) || os(Android) || os(FreeBSD)
-    import Glibc
+#if canImport(Darwin)
+import Darwin
 #else
 #else
-    import Darwin
+import Glibc
 #endif
 #endif
 
 
 public protocol _UInt8Type {}
 public protocol _UInt8Type {}