Explorar o código

For invalid input return input instead of crash

Marcin Krzyżanowski %!s(int64=9) %!d(string=hai) anos
pai
achega
849f85ff7b
Modificáronse 1 ficheiros con 5 adicións e 0 borrados
  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