2
0
Эх сурвалжийг харах

For invalid input return input instead of crash

Marcin Krzyżanowski 9 жил өмнө
parent
commit
849f85ff7b

+ 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