diff --git a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs index 1d1f036c..3e44ff89 100644 --- a/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs +++ b/src/SharpCompress/Compressors/LZMA/AesDecoderStream.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Security.Cryptography; using System.Text; @@ -20,6 +20,11 @@ namespace SharpCompress.Compressors.LZMA 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; diff --git a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs index 75bec5cf..d9d2443a 100644 --- a/tests/SharpCompress.Test/Rar/RarArchiveTests.cs +++ b/tests/SharpCompress.Test/Rar/RarArchiveTests.cs @@ -17,12 +17,24 @@ namespace SharpCompress.Test.Rar 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() { diff --git a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs index c0e8a391..ad1c71ed 100644 --- a/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs +++ b/tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs @@ -41,6 +41,11 @@ namespace SharpCompress.Test.SevenZip 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");