Browse Source

integerFromBitsArray<T> crash on Beta7, so disabled.

Marcin Krzyżanowski 11 years ago
parent
commit
95f805393a

+ 8 - 1
CryptoSwift/ByteExtension.swift

@@ -33,7 +33,14 @@ extension Byte {
 extension Byte {
 
     init(bits: [Bit]) {
-        self.init(integerFromBitsArray(bits) as Byte)
+        var bitPattern = 0 as Byte
+        for (idx,b) in enumerate(bits) {
+            if (b == Bit.One) {
+                let bit = Byte(1 << idx)
+                bitPattern = bitPattern | bit
+            }
+        }
+        self.init(bitPattern)
     }
     
     /** array of bits */

+ 12 - 11
CryptoSwift/Generics.swift

@@ -8,17 +8,18 @@
 
 import Foundation
 
-/** build bit pattern from array of bits */
-func integerFromBitsArray<T : UnsignedIntegerType>(bits: [Bit]) -> T {
-    var bitPattern:T = 0
-    for (idx,b) in enumerate(bits) {
-        if (b == Bit.One) {
-            var bit = (UInt(1) << UInt(idx)) as T
-            bitPattern = bitPattern | bit
-        }
-    }
-    return bitPattern
-}
+//FIXME: I can't do this Generic since Beta7, fix it if you can
+///** build bit pattern from array of bits */
+//func integerFromBitsArray<T : UnsignedIntegerType>(bits: [Bit]) -> T {
+//    var bitPattern:T = 0
+//    for (idx,b) in enumerate(bits) {
+//        if (b == Bit.One) {
+//            let bit = (UInt(1) << UInt(idx)) as T
+//            bitPattern = bitPattern | bit
+//        }
+//    }
+//    return bitPattern
+//}
 
 /** initialize integer from array of bytes */
 func integerWithBytes<T: IntegerType>(bytes: [Byte]) -> T {

+ 7 - 17
CryptoSwift/IntExtension.swift

@@ -16,23 +16,13 @@
 
 import Foundation
 
-func buildBitPattern<T : IntegerType, UnsignedIntegerType, BitwiseOperationsType, IntegerLiteralConvertible>(bits: [Bit]) -> T {
-        var bitPattern:T = 0
-        for (idx,b) in enumerate(bits) {
-            if (b == Bit.Zero) {
-                var bit = (1 << idx) as T
-                bitPattern = bitPattern | bit
-            }
-        }
-    return bitPattern
-}
-
-/* array of bits */
-extension Int {
-    init(bits: [Bit]) {
-        self.init(bitPattern: integerFromBitsArray(bits) as UInt)
-    }
-}
+//FIXME: see integerFromBitsArray
+///* array of bits */
+//extension Int {
+//    init(bits: [Bit]) {
+//        self.init(bitPattern: integerFromBitsArray(bits) as UInt)
+//    }
+//}
 
 /* array of bytes */
 extension Int {

+ 0 - 1
CryptoSwift/Playground/MyPlayground.playground/section-1.swift

@@ -1,4 +1,3 @@
 // Playground - noun: a place where people can play
 
 import Foundation
-

+ 0 - 9
CryptoSwift/Playground/MyPlayground.playground/timeline.xctimeline

@@ -2,14 +2,5 @@
 <Timeline
    version = "3.0">
    <TimelineItems>
-      <LoggerValueHistoryTimelineItem
-         documentLocation = "file:///Users/marcinkrzyzanowski/Devel/CryptoSwift/CryptoSwift/Playground/MyPlayground.playground#CharacterRangeLen=0&amp;CharacterRangeLoc=71&amp;EndingLineNumber=3&amp;StartingLineNumber=3&amp;Timestamp=431365313.142192">
-      </LoggerValueHistoryTimelineItem>
-      <LoggerValueHistoryTimelineItem
-         documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=71&amp;EndingColumnNumber=7&amp;EndingLineNumber=3&amp;StartingColumnNumber=5&amp;StartingLineNumber=3&amp;Timestamp=431365313.142423">
-      </LoggerValueHistoryTimelineItem>
-      <LoggerValueHistoryTimelineItem
-         documentLocation = "#CharacterRangeLen=0&amp;CharacterRangeLoc=71&amp;EndingColumnNumber=20&amp;EndingLineNumber=3&amp;StartingColumnNumber=17&amp;StartingLineNumber=3&amp;Timestamp=431365313.142639">
-      </LoggerValueHistoryTimelineItem>
    </TimelineItems>
 </Timeline>

+ 3 - 4
CryptoSwift/Poly1305.swift

@@ -163,7 +163,7 @@ public class Poly1305 {
     }
     
     public func finish(inout mac:[Byte]) -> Bool {
-        if (h.count != 16) {
+        if (mac.count != 16) {
             return false
         }
         
@@ -235,9 +235,8 @@ public class Poly1305 {
         }
     }
     
-    public func auth(mac:[Byte], m:[Byte]) {
+    public func auth(inout mac:[Byte], m:[Byte]) {
         update(m)
-        var macLocal = mac
-        finish(&macLocal)
+        finish(&mac)
     }
 }

+ 1 - 1
CryptoSwift/SHA2.swift

@@ -73,7 +73,7 @@ class SHA2 : CryptoSwift.HashBase {
         }
     }
     
-    //TODO: I can't do generict out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
+    //FIXME: I can't do Generic fuct out of calculate32 and calculate64 (UInt32 vs UInt64), but if you can - please do pull request.
     func calculate32(variant: SHA2.variant) -> NSData {
         var tmpMessage = self.prepare()
         

+ 4 - 2
CryptoSwiftTests/CipherTests.swift

@@ -49,8 +49,10 @@ class CipherTests: XCTestCase {
         
         
         let poly = Poly1305(key: key);
-        let mac:[Byte] = [Byte](count: 16, repeatedValue: 0);
-        poly.auth(mac, m: msg)
+        var mac:[Byte] = [Byte](count: 16, repeatedValue: 0);
+        poly.auth(&mac, m: msg)
+        println(mac)
+        println("QQ")
     }
 
     func testChaCha20() {