Browse Source

fix some new deprecation warnings

this is some of the low-hanging fruit; 'Bit' and C-style for loops still generate warnings under the Xcode 7.3 beta
Evan Maloney 9 years ago
parent
commit
38e3f12134

+ 1 - 10
Sources/CryptoSwift/BytesSequence.swift

@@ -6,15 +6,6 @@
 //  Copyright © 2015 Marcin Krzyzanowski. All rights reserved.
 //
 
-//TODO: func anyGenerator is renamed to AnyGenerator in Swift 2.2, until then it's just dirty hack for linux (because swift >= 2.2 is available for Linux)
-private func CS_AnyGenerator<Element>(body: () -> Element?) -> AnyGenerator<Element> {
- #if os(Linux)
-    return AnyGenerator(body: body)
- #else
-     return anyGenerator(body)
- #endif
-}
-
 struct BytesSequence: SequenceType {
     let chunkSize: Int
     let data: [UInt8]
@@ -23,7 +14,7 @@ struct BytesSequence: SequenceType {
         
         var offset:Int = 0
         
-        return CS_AnyGenerator {
+        return AnyGenerator {
             let end = min(self.chunkSize, self.data.count - offset)
             let result = self.data[offset..<offset + end]
             offset += result.count

+ 4 - 2
Sources/CryptoSwift/CipherBlockMode.swift

@@ -212,7 +212,8 @@ private struct CTRMode: BlockMode {
         var out:[UInt8] = [UInt8]()
         out.reserveCapacity(blocks.count * blocks[blocks.startIndex].count)
         for plaintext in blocks {
-            let nonce = buildNonce(iv, counter: UInt64(counter++))
+            let nonce = buildNonce(iv, counter: UInt64(counter))
+            counter += 1
             if let encrypted = cipherOperation(block: nonce) {
                 out.appendContentsOf(xor(plaintext, encrypted))
             }
@@ -229,7 +230,8 @@ private struct CTRMode: BlockMode {
         var out = [UInt8]()
         out.reserveCapacity(blocks.count * blocks[blocks.startIndex].count)
         for ciphertext in blocks {
-            let nonce = buildNonce(iv, counter: UInt64(counter++))
+            let nonce = buildNonce(iv, counter: UInt64(counter))
+            counter += 1
             if let decrypted = cipherOperation(block: nonce) {
                 out.appendContentsOf(xor(decrypted, ciphertext))
             }

+ 2 - 2
Sources/CryptoSwift/HashProtocol.swift

@@ -26,8 +26,8 @@ extension HashProtocol {
         var counter = 0
         
         while msgLength % len != (len - 8) {
-            counter++
-            msgLength++
+            counter += 1
+            msgLength += 1
         }
 
         tmpMessage += Array<UInt8>(count: counter, repeatedValue: 0)

+ 6 - 6
Sources/CryptoSwift/Rabbit.swift

@@ -64,12 +64,12 @@ final public class Rabbit {
         
         // Key divided into 8 subkeys
         var k = [UInt32](count: 8, repeatedValue: 0)
-        for var j = 0; j < 8; j++ {
+        for var j = 0; j < 8; j += 1 {
             k[j] = UInt32(key[Rabbit.blockSize - (2*j + 1)]) | (UInt32(key[Rabbit.blockSize - (2*j + 2)]) << 8)
         }
         
         // Initialize state and counter variables from subkeys
-        for var j = 0; j < 8; j++ {
+        for var j = 0; j < 8; j += 1 {
             if j % 2 == 0 {
                 x[j] = (k[(j+1) % 8] << 16) | k[j]
                 c[j] = (k[(j+4) % 8] << 16) | k[(j+5) % 8]
@@ -86,7 +86,7 @@ final public class Rabbit {
         nextState()
         
         // Reinitialize counter variables
-        for var j = 0; j < 8; j++ {
+        for var j = 0; j < 8; j += 1 {
             c[j] = c[j] ^ x[(j+4) % 8]
         }
         
@@ -123,7 +123,7 @@ final public class Rabbit {
     private func nextState() {
         // Before an iteration the counters are incremented
         var carry = p7
-        for var j = 0; j < 8; j++ {
+        for var j = 0; j < 8; j += 1 {
             let prev = c[j]
             c[j] = prev &+ a[j] &+ carry
             carry = prev > c[j] ? 1 : 0 // detect overflow
@@ -163,7 +163,7 @@ final public class Rabbit {
         output16[0] = UInt16(truncatingBitPattern: x[6] >> 16) ^ UInt16(truncatingBitPattern: x[1])
         
         var output8 = [UInt8](count: Rabbit.blockSize, repeatedValue: 0)
-        for var j = 0; j < output16.count; j++ {
+        for var j = 0; j < output16.count; j += 1 {
             output8[j * 2] = UInt8(truncatingBitPattern: output16[j] >> 8)
             output8[j * 2 + 1] = UInt8(truncatingBitPattern: output16[j])
         }
@@ -176,7 +176,7 @@ final public class Rabbit {
         
         var result = [UInt8](count: bytes.count, repeatedValue: 0)
         var output = nextOutput()
-        for var byteIdx = 0, outputIdx = 0; byteIdx < bytes.count; byteIdx++, outputIdx++ {
+        for var byteIdx = 0, outputIdx = 0; byteIdx < bytes.count; byteIdx += 1, outputIdx += 1 {
             if (outputIdx == Rabbit.blockSize) {
                 output = nextOutput()
                 outputIdx = 0