Jelajahi Sumber

Handle unused returned value by updating internal API

Marcin Krzyżanowski 9 tahun lalu
induk
melakukan
4865e18e28

+ 1 - 1
CryptoSwiftTests/ExtensionsTest.swift

@@ -22,7 +22,7 @@ final class ExtensionsTest: XCTestCase {
         measureMetrics([XCTPerformanceMetric_WallClockTime], automaticallyStartMeasuring: false, for: { () -> Void in
             let message = Array<UInt8>(repeating: 7, count: 1024 * 1024)
             self.startMeasuring()
-            message.chunks(chunksize: AES.blockSize)
+            _ = message.chunks(chunksize: AES.blockSize)
             self.stopMeasuring()
         })
     }

+ 1 - 1
CryptoSwiftTests/HashTests.swift

@@ -46,7 +46,7 @@ final class CryptoSwiftTests: XCTestCase {
             let data = NSData(bytes: buf, length: 1024 * 1024)
             let arr = data.arrayOfBytes()
             self.startMeasuring()
-                Hash.md5(arr).calculate()
+                _ = Hash.md5(arr).calculate()
             self.stopMeasuring()
             buf?.deallocateCapacity(1024 * 1024)
             buf?.deinitialize()

+ 1 - 1
Sources/CryptoSwift/HMAC.swift

@@ -26,7 +26,7 @@ final public class HMAC {
             }
         }
         
-        func calculateHash(bytes bytes:Array<UInt8>) -> Array<UInt8>? {
+        func calculateHash(bytes:Array<UInt8>) -> Array<UInt8>? {
             switch (self) {
             case .sha1:
                 return Hash.sha1(bytes).calculate()

+ 8 - 10
Sources/CryptoSwift/IntExtension.swift

@@ -51,21 +51,20 @@ extension Int {
 extension Int {
     
     /** Shift bits to the left. All bits are shifted (including sign bit) */
-    private mutating func shiftLeft(count: Int) -> Int {
+    private mutating func shiftLeft(by count: Int) {
         self = CryptoSwift.shiftLeft(value: self, count: count) //FIXME: count:
-        return self
     }
     
     /** Shift bits to the right. All bits are shifted (including sign bit) */
-    private mutating func shiftRight(count: Int) -> Int {
+    private mutating func shiftRight(by count: Int) {
         if (self == 0) {
-            return self;
+            return
         }
         
         let bitsCount = sizeofValue(self) * 8
 
         if (count >= bitsCount) {
-            return 0
+            return
         }
 
         let maxBitsForValue = Int(floor(log2(Double(self)) + 1))
@@ -80,7 +79,6 @@ extension Int {
             }
         }
         self = Int(shiftedValue)
-        return self
     }
 }
 
@@ -88,13 +86,13 @@ extension Int {
 
 /** shift left and assign with bits truncation */
 public func &<<= (lhs: inout Int, rhs: Int) {
-    lhs.shiftLeft(count: rhs)
+    lhs.shiftLeft(by: rhs)
 }
 
 /** shift left with bits truncation */
 public func &<< (lhs: Int, rhs: Int) -> Int {
     var l = lhs;
-    l.shiftLeft(count: rhs)
+    l.shiftLeft(by: rhs)
     return l
 }
 
@@ -102,12 +100,12 @@ public func &<< (lhs: Int, rhs: Int) -> Int {
 
 /** shift right and assign with bits truncation */
 func &>>= (lhs: inout Int, rhs: Int) {
-    lhs.shiftRight(count: rhs)
+    lhs.shiftRight(by: rhs)
 }
 
 /** shift right and assign with bits truncation */
 func &>> (lhs: Int, rhs: Int) -> Int {
     var l = lhs;
-    l.shiftRight(count: rhs)
+    l.shiftRight(by: rhs)
     return l
 }

+ 10 - 13
Sources/CryptoSwift/Poly1305.swift

@@ -183,9 +183,10 @@ final public class Poly1305 {
     
     // MARK: - Utils
     
-    private func add(context:Context, c:Array<UInt8>) -> Bool {
+    private func add(context:Context, c:Array<UInt8>) {
         if (context.h.count != 17 && c.count != 17) {
-            return false
+            assertionFailure()
+            return
         }
         
         var u:UInt16 = 0
@@ -194,12 +195,13 @@ final public class Poly1305 {
             context.h[i] = UInt8.withValue(v: u)
             u = u >> 8
         }
-        return true
+        return
     }
     
-    private func squeeze(context:Context, hr:Array<UInt32>) -> Bool {
+    private func squeeze(context:Context, hr:Array<UInt32>) {
         if (context.h.count != 17 && hr.count != 17) {
-            return false
+            assertionFailure()
+            return
         }
         
         var u:UInt32 = 0
@@ -220,14 +222,12 @@ final public class Poly1305 {
             u >>= 8
         }
         context.h[16] += UInt8.withValue(v: u);
-        
-        return true
     }
     
-    private func freeze(context:Context) -> Bool {
+    private func freeze(context:Context) {
         assert(context.h.count == 17,"Invalid length")
         if (context.h.count != 17) {
-            return false
+            return
         }
         
         let minusp:Array<UInt8> = [0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xfc]
@@ -250,11 +250,9 @@ final public class Poly1305 {
         for i in 0..<17 {
             context.h[i] ^= negative & (horig[i] ^ context.h[i]);
         }
-        
-        return true;
     }
     
-    private func blocks(context:Context, m:Array<UInt8>, startPos:Int = 0) -> Int {
+    private func blocks(context:Context, m:Array<UInt8>, startPos:Int = 0) {
         var bytes = m.count
         let hibit = context.final ^ 1 // 1 <<128
         var mPos = startPos
@@ -291,6 +289,5 @@ final public class Poly1305 {
             mPos += blockSize
             bytes -= blockSize
         }
-        return mPos
     }
 }

+ 9 - 11
Sources/CryptoSwift/UInt32Extension.swift

@@ -36,9 +36,9 @@ extension UInt32 {
 extension UInt32 {
     
     /** Shift bits to the left. All bits are shifted (including sign bit) */
-    private mutating func shiftLeft(count: UInt32) -> UInt32 {
+    private mutating func shiftLeft(by count: UInt32) {
         if (self == 0) {
-            return self;
+            return
         }
         
         let bitsCount = UInt32(sizeof(UInt32) * 8)
@@ -59,19 +59,18 @@ extension UInt32 {
         }
 
         self = shiftedValue
-        return self
     }
     
     /** Shift bits to the right. All bits are shifted (including sign bit) */
-    private mutating func shiftRight(count: UInt32) -> UInt32 {
+    private mutating func shiftRight(by count: UInt32) {
         if (self == 0) {
-            return self;
+            return
         }
         
         let bitsCount = UInt32(sizeofValue(self) * 8)
 
         if (count >= bitsCount) {
-            return 0
+            return
         }
 
         let maxBitsForValue = UInt32(floor(log2(Double(self)) + 1))
@@ -86,31 +85,30 @@ extension UInt32 {
             }
         }
         self = shiftedValue
-        return self
     }
 
 }
 
 /** shift left and assign with bits truncation */
 public func &<<= (lhs: inout UInt32, rhs: UInt32) {
-    lhs.shiftLeft(count: rhs)
+    lhs.shiftLeft(by: rhs)
 }
 
 /** shift left with bits truncation */
 public func &<< (lhs: UInt32, rhs: UInt32) -> UInt32 {
     var l = lhs;
-    l.shiftLeft(count: rhs)
+    l.shiftLeft(by: rhs)
     return l
 }
 
 /** shift right and assign with bits truncation */
 func &>>= (lhs: inout UInt32, rhs: UInt32) {
-    lhs.shiftRight(count: rhs)
+    lhs.shiftRight(by: rhs)
 }
 
 /** shift right and assign with bits truncation */
 func &>> (lhs: UInt32, rhs: UInt32) -> UInt32 {
     var l = lhs;
-    l.shiftRight(count: rhs)
+    l.shiftRight(by: rhs)
     return l
 }

+ 4 - 5
Sources/CryptoSwift/UInt8Extension.swift

@@ -82,15 +82,15 @@ extension UInt8 {
 /** Shift bits */
 extension UInt8 {
     /** Shift bits to the right. All bits are shifted (including sign bit) */
-    mutating func shiftRight(count: UInt8) -> UInt8 {
+    mutating func shiftRight(by count: UInt8) {
         if (self == 0) {
-            return self;
+            return
         }
 
         let bitsCount = UInt8(sizeof(UInt8) * 8)
 
         if (count >= bitsCount) {
-            return 0
+            return
         }
 
         let maxBitsForValue = UInt8(floor(log2(Double(self) + 1)))
@@ -104,13 +104,12 @@ extension UInt8 {
             }
         }
         self = shiftedValue
-        return self
     }
 }
 
 /** shift right and assign with bits truncation */
 func &>> (lhs: UInt8, rhs: UInt8) -> UInt8 {
     var l = lhs;
-    l.shiftRight(count: rhs)
+    l.shiftRight(by: rhs)
     return l
 }