Explorar o código

Fix compile error for Xcode 8 GM/Swift 3.0 (#325)

* Fix `@escaping` compile error
* Resolve complexity compile error
Masayuki Ono %!s(int64=9) %!d(string=hai) anos
pai
achega
c73aec8f3e

+ 1 - 1
Sources/CryptoSwift/BlockMode/BlockMode.swift

@@ -11,7 +11,7 @@ typealias CipherOperationOnBlock = (_ block: Array<UInt8>) -> Array<UInt8>?
 public enum BlockMode {
     case ECB, CBC, PCBC, CFB, OFB, CTR
 
-    func worker(_ iv: Array<UInt8>?, cipherOperation: CipherOperationOnBlock) -> BlockModeWorker {
+    func worker(_ iv: Array<UInt8>?, cipherOperation: @escaping CipherOperationOnBlock) -> BlockModeWorker {
         switch (self) {
         case .ECB:
             return ECBModeWorker(iv: iv ?? [], cipherOperation: cipherOperation)

+ 1 - 1
Sources/CryptoSwift/BlockMode/CBC.swift

@@ -15,7 +15,7 @@ struct CBCModeWorker: BlockModeWorker {
     private let iv: Element
     private var prev: Element?
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.iv = iv
         self.cipherOperation = cipherOperation
     }

+ 1 - 1
Sources/CryptoSwift/BlockMode/CFB.swift

@@ -15,7 +15,7 @@ struct CFBModeWorker: BlockModeWorker {
     private let iv: Element
     private var prev: Element?
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.iv = iv
         self.cipherOperation = cipherOperation
     }

+ 1 - 1
Sources/CryptoSwift/BlockMode/CTR.swift

@@ -15,7 +15,7 @@ struct CTRModeWorker: RandomAccessBlockModeWorker {
     private let iv: Element
     var counter: UInt = 0
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.iv = iv
         self.cipherOperation = cipherOperation
     }

+ 1 - 1
Sources/CryptoSwift/BlockMode/ECB.swift

@@ -12,7 +12,7 @@ struct ECBModeWorker: BlockModeWorker {
     typealias Element = Array<UInt8>
     let cipherOperation: CipherOperationOnBlock
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.cipherOperation = cipherOperation
     }
 

+ 1 - 1
Sources/CryptoSwift/BlockMode/OFB.swift

@@ -15,7 +15,7 @@ struct OFBModeWorker: BlockModeWorker {
     private let iv: Element
     private var prev: Element?
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.iv = iv
         self.cipherOperation = cipherOperation
     }

+ 1 - 1
Sources/CryptoSwift/BlockMode/PCBC.swift

@@ -15,7 +15,7 @@ struct PCBCModeWorker: BlockModeWorker {
     private let iv: Element
     private var prev: Element?
 
-    init(iv: Array<UInt8>, cipherOperation: CipherOperationOnBlock) {
+    init(iv: Array<UInt8>, cipherOperation: @escaping CipherOperationOnBlock) {
         self.iv = iv
         self.cipherOperation = cipherOperation
     }

+ 3 - 1
Tests/CryptoSwiftTests/ExtensionsTest.swift

@@ -60,7 +60,9 @@ final class ExtensionsTest: XCTestCase {
         let ii:Int = 21
         XCTAssert(ii &<< 1 == ii << 1, "shift left failed")
         XCTAssert(ii &<< 8 == ii << 8, "shift left failed")
-        XCTAssert(ii &<< ((MemoryLayout<Int>.size * 8) - 1) == ii << ((MemoryLayout<Int>.size * 8) - 1), "shift left failed")
+        let shiftLeft1 = ii &<< ((MemoryLayout<Int>.size * 8) - 1)
+        let shiftLeft2 = ii << ((MemoryLayout<Int>.size * 8) - 1)
+        XCTAssert(shiftLeft1 == shiftLeft2, "shift left failed")
         XCTAssert(ii &<< ((MemoryLayout<Int>.size * 8)) == 0, "shift left failed")
         
         let iii:UInt32 = 21