Jelajahi Sumber

isEmpty in place of count > 0

Marcin Krzyżanowski 9 tahun lalu
induk
melakukan
d9765441f6

+ 2 - 2
Sources/CryptoSwift/AES.swift

@@ -95,7 +95,7 @@ final public class AES: BlockCipher {
         self.blockMode = blockMode
         self.padding = padding
 
-        if let iv = iv where iv.count > 0 {
+        if let iv = iv where !iv.isEmpty {
             self.iv = iv
         } else {
             let defaultIV = [UInt8](count: AES.blockSize, repeatedValue: 0)
@@ -445,7 +445,7 @@ extension AES {
         }
 
         mutating public func update(withBytes bytes:[UInt8], isLast: Bool = false) throws -> [UInt8] {
-            if bytes.count == 0 {
+            if bytes.isEmpty {
                 return bytes;
             }
 

+ 1 - 1
Sources/CryptoSwift/Array+Extension.swift

@@ -17,7 +17,7 @@ extension Array {
             words.append(word)
         }
         let reminder = Array(self.suffix(self.count % chunksize))
-        if (reminder.count > 0) {
+        if !reminder.isEmpty {
             words.append(reminder)
         }
         return words

+ 1 - 1
Sources/CryptoSwift/BytesSequence.swift

@@ -18,7 +18,7 @@ struct BytesSequence: SequenceType {
             let end = min(self.chunkSize, self.data.count - offset)
             let result = self.data[offset..<offset + end]
             offset += result.count
-            return result.count > 0 ? result : nil
+            return !result.isEmpty ? result : nil
         }
     }
 }

+ 3 - 1
Sources/CryptoSwift/PKCS5/PBKDF2.swift

@@ -6,6 +6,8 @@
 //  Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
 //
 
+import Darwin
+
 public extension PKCS5 {
     /// A key derivation function.
     ///
@@ -31,7 +33,7 @@ public extension PKCS5 {
         public init(password: [UInt8], salt: [UInt8], iterations: Int = 4096 /* c */, keyLength: Int? = nil /* dkLen */, variant: HMAC.Variant = .sha256) throws {
             precondition(iterations > 0)
             
-            guard let prf = HMAC(key: password, variant: variant) where iterations > 0 && password.count > 0 && salt.count > 0 else {
+            guard let prf = HMAC(key: password, variant: variant) where iterations > 0 && !password.isEmpty && !salt.isEmpty else {
                 throw Error.InvalidInput
             }
 

+ 2 - 2
Sources/CryptoSwift/PKCS7.swift

@@ -37,8 +37,8 @@ public struct PKCS7: Padding {
     }
 
     public func remove(bytes: [UInt8], blockSize:Int?) -> [UInt8] {
-        assert(bytes.count > 0, "Need bytes to remove padding")
-        guard bytes.count > 0, let lastByte = bytes.last else {
+        assert(!bytes.isEmpty, "Need bytes to remove padding")
+        guard !bytes.isEmpty, let lastByte = bytes.last else {
             return bytes
         }