浏览代码

Adapt to new rules of Swift 1.2 Part#2

Marcin Krzyżanowski 10 年之前
父节点
当前提交
a4be07f1b5

+ 3 - 3
CryptoSwift/Generics.swift

@@ -61,7 +61,7 @@ func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
     var valuePointer = UnsafeMutablePointer<T>.alloc(1)
     valuePointer.memory = value
     
-    var bytesPointer = UnsafeMutablePointer<Byte>(valuePointer)
+    var bytesPointer = UnsafeMutablePointer<UInt8>(valuePointer)
     var bytes = [UInt8](count: totalBytes, repeatedValue: 0)
     for j in 0..<min(sizeof(T),totalBytes) {
         bytes[totalBytes - 1 - j] = (bytesPointer + j).memory
@@ -77,13 +77,13 @@ func arrayOfBytes<T>(value:T, length:Int? = nil) -> [UInt8] {
 
 // helper to be able tomake shift operation on T
 func <<<T:SignedIntegerType>(lhs: T, rhs: Int) -> Int {
-    let a = lhs as Int
+    let a = lhs as! Int
     let b = rhs
     return a << b
 }
 
 func <<<T:UnsignedIntegerType>(lhs: T, rhs: Int) -> UInt {
-    let a = lhs as UInt
+    let a = lhs as! UInt
     let b = rhs
     return a << b
 }

+ 1 - 1
CryptoSwift/IntExtension.swift

@@ -30,7 +30,7 @@ extension Int {
         return arrayOfBytes(self, length: totalBytes)
     }
 
-    public static func withBytes(bytes: Slice<Byte>) -> Int {
+    public static func withBytes(bytes: Slice<UInt8>) -> Int {
         return Int.withBytes(Array(bytes))
     }
 

+ 2 - 3
CryptoSwift/MD5.swift

@@ -56,9 +56,8 @@ class MD5 : CryptoSwift.HashBase {
             
             // break chunk into sixteen 32-bit words M[j], 0 ≤ j ≤ 15
             var M:[UInt32] = [UInt32](count: 16, repeatedValue: 0)
-            for x in 0..<M.count {
-                chunk.getBytes(&M[x], range:NSRange(location:x * sizeofValue(M[x]), length: sizeofValue(M[x])));
-            }
+            let range = NSRange(location:0, length: M.count * sizeof(UInt32))
+            chunk.getBytes(UnsafeMutablePointer<Void>(M), range: range)
             
             // Initialize hash value for this chunk:
             var A:UInt32 = hh[0]

+ 1 - 1
CryptoSwift/NSDataExtension.swift

@@ -86,7 +86,7 @@ extension NSData {
         
         var s:String = "";
         for byte in bytesArray {
-            s = s + NSString(format:"%02X", byte)
+            s = s + String(format:"%02X", byte)
         }
         return s;
     }

+ 2 - 2
CryptoSwift/PKCS7.swift

@@ -16,7 +16,7 @@ public struct PKCS7 {
     }
     
     public func addPadding(blockSizeBytes:UInt8) -> NSData {
-        var padding = blockSizeBytes - (data.length % Int(blockSizeBytes))
+        var padding = UInt8(blockSizeBytes) - (UInt8(data.length) % UInt8(blockSizeBytes))
         var withPadding = NSMutableData(data: data)
         if (padding == 0) {
             // If the original data is a multiple of N bytes, then an extra block of bytes with value N is added.
@@ -33,7 +33,7 @@ public struct PKCS7 {
     }
     
     public func removePadding() -> NSData {
-        var padding:Byte = 0
+        var padding:UInt8 = 0
         data.subdataWithRange(NSRange(location: data.length - 1, length: 1)).getBytes(&padding, length: 1)
         
         if padding >= 1 {

+ 1 - 1
CryptoSwiftTests/ChaCha20Tests.swift

@@ -51,7 +51,7 @@ class ChaCha20Tests: XCTestCase {
             
             let expectedHex = expectedHexes[idx]
             //println(countElements(expectedHex) / 2);
-            let message = [UInt8](count: (countElements(expectedHex) / 2), repeatedValue: 0)
+            let message = [UInt8](count: (count(expectedHex) / 2), repeatedValue: 0)
             let messageData = NSData(bytes: message, length: message.count);
             
             let setup = (key: keyData, iv: ivData)

+ 2 - 2
CryptoSwiftTests/HashTests.swift

@@ -76,7 +76,7 @@ class CryptoSwiftTests: XCTestCase {
     
     func testMD5PerformanceSwift() {
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
-            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(UInt8))))
+            let buf = UnsafeMutablePointer<UInt8>(calloc(2048, UInt(sizeof(UInt8))))
             let data = NSData(bytes: buf, length: 2048)
             self.startMeasuring()
             for _ in [0...1000] {
@@ -90,7 +90,7 @@ class CryptoSwiftTests: XCTestCase {
     
     func testMD5PerformanceCommonCrypto() {
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, forBlock: { () -> Void in
-            let buf = UnsafeMutablePointer<Byte>(calloc(2048, UInt(sizeof(UInt8))))
+            let buf = UnsafeMutablePointer<UInt8>(calloc(2048, UInt(sizeof(UInt8))))
             let data = NSData(bytes: buf, length: 2048)
             self.startMeasuring()
             for _ in [0...1000] {