fix tests

This commit is contained in:
Adam Hathcock
2024-04-22 14:57:08 +01:00
parent 7963233702
commit f24bfdf945
3 changed files with 8 additions and 7 deletions

View File

@@ -130,12 +130,12 @@ public class SevenZipArchive : AbstractArchive<SevenZipArchiveEntry, SevenZipVol
IEnumerable<SevenZipVolume> volumes
)
{
var stream = volumes.Single().Stream;
LoadFactory(stream);
if (database is null)
{
return Enumerable.Empty<SevenZipArchiveEntry>();
}
var stream = volumes.Single().Stream;
LoadFactory(stream);
var entries = new SevenZipArchiveEntry[database._files.Count];
for (var i = 0; i < database._files.Count; i++)
{
@@ -260,6 +260,6 @@ public class SevenZipArchive : AbstractArchive<SevenZipArchiveEntry, SevenZipVol
public PasswordProvider(string? password) => _password = password;
public string CryptoGetTextPassword() => _password.NotNull();
public string? CryptoGetTextPassword() => _password;
}
}

View File

@@ -20,7 +20,8 @@ internal sealed class AesDecoderStream : DecoderStream2
public AesDecoderStream(Stream input, byte[] info, IPasswordProvider pass, long limit)
{
if (pass.CryptoGetTextPassword() == null)
var password = pass.CryptoGetTextPassword();
if (password == null)
{
throw new SharpCompress.Common.CryptographicException(
"Encrypted 7Zip archive has no password specified."
@@ -37,8 +38,8 @@ internal sealed class AesDecoderStream : DecoderStream2
Init(info, out var numCyclesPower, out var salt, out var seed);
var password = Encoding.Unicode.GetBytes(pass.CryptoGetTextPassword());
var key = InitKey(numCyclesPower, salt, password);
var passwordBytes = Encoding.Unicode.GetBytes(password);
var key = InitKey(numCyclesPower, salt, passwordBytes);
if (key == null)
{
throw new InvalidOperationException("Initialized with null key");

View File

@@ -2,5 +2,5 @@ namespace SharpCompress.Compressors.LZMA.Utilites;
internal interface IPasswordProvider
{
string CryptoGetTextPassword();
string? CryptoGetTextPassword();
}