Skip to content

Commit

Permalink
Unit test for ZipInputStream.CanDecompressEntry being false for AES e…
Browse files Browse the repository at this point in the history
…ncrypted entries.
  • Loading branch information
Numpsy committed Feb 2, 2020
1 parent a86f919 commit fe6dd33
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipEncryptionHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,40 @@ public void ZipFileStoreAesPartialRead()
}
}

/// <summary>
/// ZipInputStream can't decrypt AES encrypted entries, but it should repot that to the caller
/// rather than just failing.
/// </summary>
[Test]
[Category("Zip")]
public void ZipinputStreamShouldGracefullyFailWithAESStreams()
{
string password = "password";

using (var memoryStream = new MemoryStream())
{
// Try to create a zip stream
WriteEncryptedZipToStream(memoryStream, password, 256);

// reset
memoryStream.Seek(0, SeekOrigin.Begin);

// Try to read
using (var inputStream = new ZipInputStream(memoryStream))
{
inputStream.Password = password;
var entry = inputStream.GetNextEntry();
Assert.That(entry.AESKeySize, Is.EqualTo(256), "Test entry should be AES256 encrypted.");

// CanDecompressEntry should be false.
Assert.That(inputStream.CanDecompressEntry, Is.False, "CanDecompressEntry should be false for AES encrypted entries");

// Should throw on read.
Assert.Throws<ZipException>(() => inputStream.ReadByte());
}
}
}

private static readonly string[] possible7zPaths = new[] {
// Check in PATH
"7z", "7za",
Expand Down

0 comments on commit fe6dd33

Please sign in to comment.