Browse Source

Update for DEVELOPMENT-SNAPSHOT-2016-07-28-a

Marcin Krzyżanowski 9 years ago
parent
commit
0b9357731a

+ 1 - 1
.swift-version

@@ -1 +1 @@
-DEVELOPMENT-SNAPSHOT-2016-07-25-a
+DEVELOPMENT-SNAPSHOT-2016-07-28-a

+ 6 - 8
CryptoSwiftTests/HashTests.swift

@@ -51,17 +51,15 @@ final class CryptoSwiftTests: XCTestCase {
     
     func testMD5PerformanceCommonCrypto() {
         self.measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
-            let buf = UnsafeMutablePointer<UInt8>(calloc(1024 * 1024, sizeof(UInt8.self)))
+            let buf: UnsafeMutableRawPointer = calloc(1024 * 1024, sizeof(UInt8.self))
             let data = NSData(bytes: buf, length: 1024 * 1024)
-            let outbuf = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
+            let md = UnsafeMutablePointer<UInt8>.allocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
             self.startMeasuring()
-                CC_MD5(data.bytes, CC_LONG(data.length), outbuf)
-            //let output = NSData(bytes: outbuf, length: Int(CC_MD5_DIGEST_LENGTH));
+            CC_MD5(data.bytes, CC_LONG(data.length), md)
             self.stopMeasuring()
-            outbuf.deallocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
-            outbuf.deinitialize()
-            buf?.deallocate(capacity:1024 * 1024)
-            buf?.deinitialize()
+            md.deallocate(capacity: Int(CC_MD5_DIGEST_LENGTH))
+            md.deinitialize()
+            buf.deallocate(bytes: 1024 * 1024, alignedTo: alignof(UInt8.self))
         })
     }
     

+ 2 - 2
Sources/CryptoSwift/Generics.swift

@@ -36,7 +36,7 @@ func integerFrom<T: UnsignedInteger>(_ bits: Array<Bit>) -> T
 /// Initialize integer from array of bytes.
 /// This method may be slow
 @_specialize(UInt32)
-func integerWith<T:Integer where T:ByteConvertible, T: BitshiftOperationsType>(_ bytes: Array<UInt8>) -> T {
+func integerWith<T:Integer>(_ bytes: Array<UInt8>) -> T where T:ByteConvertible, T: BitshiftOperationsType {
     var bytes = bytes.reversed() as Array<UInt8> //FIXME: check it this is equivalent of Array(...)
     if bytes.count < sizeof(T.self) {
         let paddingCount = sizeof(T.self) - bytes.count
@@ -96,7 +96,7 @@ func << <T:UnsignedInteger>(lhs: T, rhs: Int) -> UInt {
 // Generic function itself
 // FIXME: this generic function is not as generic as I would. It crashes for smaller types
 @_specialize(Int)
-func shiftLeft<T: SignedInteger where T: Initiable>(_ value: T, by count: Int) -> T {
+func shiftLeft<T: SignedInteger>(_ value: T, by count: Int) -> T where T: Initiable {
     if (value == 0) {
         return 0;
     }

+ 4 - 19
Sources/CryptoSwift/Operators.swift

@@ -22,22 +22,7 @@ j &<<= 2        //shift left and assign
 @see: https://medium.com/@krzyzanowskim/swiftly-shift-bits-and-protect-yourself-be33016ce071
 */
 
-infix operator &<<= {
-associativity none
-precedence 160
-}
-
-infix operator &<< {
-associativity none
-precedence 160
-}
-
-infix operator &>>= {
-associativity none
-precedence 160
-}
-
-infix operator &>> {
-associativity none
-precedence 160
-}
+infix operator &<<= : BitwiseShiftPrecedence
+infix operator &<< : BitwiseShiftPrecedence
+infix operator &>>= : BitwiseShiftPrecedence
+infix operator &>> : BitwiseShiftPrecedence