Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/ICSharpCode.SharpZipLib/Zip/ZipFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,9 @@ public void Add(ZipEntry entry)
/// <param name="dataSource">The source of the data for this entry.</param>
/// <param name="entry">The entry to add.</param>
/// <remarks>This can be used to add file entries with a custom data source.</remarks>
/// <exception cref="NotSupportedException">
/// The encryption method specified in <paramref name="entry"/> is unsupported.
/// </exception>
public void Add(IStaticDataSource dataSource, ZipEntry entry)
{
if (entry == null)
Expand All @@ -1862,6 +1865,13 @@ public void Add(IStaticDataSource dataSource, ZipEntry entry)
throw new ArgumentNullException(nameof(dataSource));
}

// We don't currently support adding entries with AES encryption, so throw
// up front instead of failing or falling back to ZipCrypto later on
if (entry.AESKeySize > 0)
{
throw new NotSupportedException("Creation of AES encrypted entries is not supported");
}

CheckUpdating();

AddUpdate(new ZipUpdate(dataSource, entry));
Expand Down
22 changes: 22 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/ZipFileHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,5 +1547,27 @@ public void HostSystemPersistedFromZipFile()
}
}
}

/// <summary>
/// Refs https://github.com/icsharpcode/SharpZipLib/issues/385
/// Trying to add an AES Encrypted entry to ZipFile should throw as it isn't supported
/// </summary>
[Test]
[Category("Zip")]
public void AddingAnAESEncryptedEntryShouldThrow()
{
var memStream = new MemoryStream();
using (ZipFile zof = new ZipFile(memStream))
{
var entry = new ZipEntry("test")
{
AESKeySize = 256
};

zof.BeginUpdate();
var exception = Assert.Throws<NotSupportedException>(() => zof.Add(new StringMemoryDataSource("foo"), entry));
Assert.That(exception.Message, Is.EqualTo("Creation of AES encrypted entries is not supported"));
}
}
}
}