assert checked too early

This commit is contained in:
Marcin Krzyżanowski
2016-06-09 12:04:49 +02:00
parent 14441e4807
commit 18385d0b35
+2 -1
View File
@@ -37,11 +37,12 @@ public struct PKCS7: Padding {
}
public func remove(data bytes: Array<UInt8>, blockSize:Int?) -> Array<UInt8> {
assert(!bytes.isEmpty, "Need bytes to remove padding")
guard !bytes.isEmpty, let lastByte = bytes.last else {
return bytes
}
assert(!bytes.isEmpty, "Need bytes to remove padding")
let padding = Int(lastByte) // last byte
let finalLength = bytes.count - padding