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
5 changes: 5 additions & 0 deletions src/SharpCompress/Archives/AbstractArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ public IReader ExtractAllEntries()
/// </summary>
public virtual bool IsSolid => false;

/// <summary>
/// Archive is ENCRYPTED (this means the Archive has password-protected files).
/// </summary>
public virtual bool IsEncrypted => false;

/// <summary>
/// The archive can find all the parts of the archive needed to fully extract the archive. This forces the parsing of the entire archive.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions src/SharpCompress/Archives/Rar/RarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ protected override IReader CreateReaderForSolidExtraction()

public override bool IsSolid => Volumes.First().IsSolidArchive;

public override bool IsEncrypted => Entries.First(x => !x.IsDirectory).IsEncrypted;

public virtual int MinVersion => Volumes.First().MinVersion;
public virtual int MaxVersion => Volumes.First().MaxVersion;

Expand Down
2 changes: 2 additions & 0 deletions src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ protected override IReader CreateReaderForSolidExtraction() =>
.GroupBy(x => x.FilePart.Folder)
.Any(folder => folder.Count() > 1);

public override bool IsEncrypted => Entries.First(x => !x.IsDirectory).IsEncrypted;

public override long TotalSize =>
_database?._packSizes.Aggregate(0L, (total, packSize) => total + packSize) ?? 0;

Expand Down
9 changes: 9 additions & 0 deletions tests/SharpCompress.Test/Rar/RarArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,13 @@ public void Rar5_Encrypted_Iterate_Archive() =>
"Rar5.encrypted_filesOnly.rar",
"Failure jpg exe Empty тест.txt jpg\\test.jpg exe\\test.exe"
);

[Fact]
public void Rar_TestEncryptedDetection()
{
using var passwordProtectedFilesArchive = RarArchive.Open(
Path.Combine(TEST_ARCHIVES_PATH, "Rar.encrypted_filesOnly.rar")
);
Assert.True(passwordProtectedFilesArchive.IsEncrypted);
}
}
9 changes: 9 additions & 0 deletions tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,15 @@ public void SevenZipArchive_Tar_PathRead()
);
}

[Fact]
public void SevenZipArchive_TestEncryptedDetection()
{
using var passwordProtectedFilesArchive = SevenZipArchive.Open(
Path.Combine(TEST_ARCHIVES_PATH, "7Zip.encryptedFiles.7z")
);
Assert.True(passwordProtectedFilesArchive.IsEncrypted);
}

[Fact]
public void SevenZipArchive_TestSolidDetection()
{
Expand Down
Binary file not shown.