浏览代码

For invalid input return input instead of crash

Marcin Krzyżanowski 9 年之前
父节点
当前提交
849f85ff7b
共有 1 个文件被更改,包括 5 次插入0 次删除
  1. 5 0
      Sources/CryptoSwift/PKCS7.swift

+ 5 - 0
Sources/CryptoSwift/PKCS7.swift

@@ -37,6 +37,11 @@ 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 else {
+            return bytes
+        }
+
         let lastByte = bytes.last!
         let padding = Int(lastByte) // last byte
         let finalLength = bytes.count - padding