Преглед на файлове

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