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
7 changes: 6 additions & 1 deletion src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
Expand All @@ -20,6 +20,11 @@ internal sealed class AesDecoderStream : DecoderStream2

public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
{
if (pass.CryptoGetTextPassword() == null)
{
throw new SharpCompress.Common.CryptographicException("Encrypted 7Zip archive has no password specified.");
}

mStream = input;
mLimit = limit;

Expand Down
12 changes: 12 additions & 0 deletions tests/SharpCompress.Test/Rar/RarArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ public void Rar_EncryptedFileAndHeader_Archive()
ReadRarPassword("Rar.encrypted_filesAndHeader.rar", "test");
}

[Fact]
public void Rar_EncryptedFileAndHeader_NoPasswordExceptionTest()
{
Assert.Throws(typeof(CryptographicException), () => ReadRarPassword("Rar.encrypted_filesAndHeader.rar", null));
}

/*[Fact]
public void Rar5_EncryptedFileAndHeader_Archive()
{
ReadRarPassword("Rar5.encrypted_filesAndHeader.rar", "test");
}*/

[Fact]
public void Rar5_EncryptedFileAndHeader_NoPasswordExceptionTest()
{
Assert.Throws(typeof(CryptographicException), () => ReadRarPassword("Rar5.encrypted_filesAndHeader.rar", null));
}

[Fact]
public void Rar_EncryptedFileOnly_Archive()
{
Expand Down
5 changes: 5 additions & 0 deletions tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public void SevenZipArchive_LZMAAES_PathRead()
ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = "testpassword" });
}
[Fact]
public void SevenZipArchive_LZMAAES_NoPasswordExceptionTest()
{
Assert.Throws(typeof(CryptographicException), () => ArchiveFileRead("7Zip.LZMA.Aes.7z", new ReaderOptions() { Password = null })); //was failing with ArgumentNullException not CryptographicException like rar
}
[Fact]
public void SevenZipArchive_PPMd_StreamRead()
{
ArchiveStreamRead("7Zip.PPMd.7z");
Expand Down