Skip to content

Commit 03bd248

Browse files
committed
Throw error on decrypt empty input data. Fixes #423
1 parent 3d49da4 commit 03bd248

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Sources/CryptoSwift/AES.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public final class AES: BlockCipher {
2020
case invalidKeyOrInitializationVector
2121
/// Invalid IV
2222
case invalidInitializationVector
23+
/// Invalid Data
24+
case invalidData
2325
}
2426

2527
public enum Variant: Int {
@@ -571,6 +573,10 @@ extension AES: Cipher {
571573

572574
var oneTimeCryptor = self.makeDecryptor()
573575
let chunks = bytes.batched(by: AES.blockSize)
576+
if chunks.count == 0 {
577+
throw Error.invalidData
578+
}
579+
574580
var out = Array<UInt8>()
575581
out.reserveCapacity(bytes.count)
576582

0 commit comments

Comments
 (0)