mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1060] [MERGED] Add archive-level password protection flags for 7z and rar #1488
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/adamhathcock/sharpcompress/pull/1060
Author: @HeroponRikiBestest
Created: 12/2/2025
Status: ✅ Merged
Merged: 12/3/2025
Merged by: @adamhathcock
Base:
master← Head:rar-7z-password📝 Commits (4)
99a6c4dAdd archive-level IsEncrypted flage0660e7Add tests1b1df86Improve logic41c3cc1Csharpier📊 Changes
6 files changed (+27 additions, -0 deletions)
View changed files
📝
src/SharpCompress/Archives/AbstractArchive.cs(+5 -0)📝
src/SharpCompress/Archives/Rar/RarArchive.cs(+2 -0)📝
src/SharpCompress/Archives/SevenZip/SevenZipArchive.cs(+2 -0)📝
tests/SharpCompress.Test/Rar/RarArchiveTests.cs(+9 -0)📝
tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs(+9 -0)➕
tests/TestArchives/Archives/7Zip.encryptedFiles.7z(+0 -0)📄 Description
Adds an encrypted flag for 7z archives and rar archives. The main reason/utility of this PR is because ExtractAllEntries is (practically) needed for solid 7z and rar archives, but an exception will be thrown if any of the files are password protected. This avoids the current requirement to pre-iterate through file entries to check for password protection.
This implementation mainly copies the logic for 7z's IsEncrypted flag. It checks the first file in the archive and checks whether it's encrypted. While it's technically possible that some later files aren't encrypted; as mentioned previously, the main utility of this flag is so that the aforementioned additional logic can be avoided for solid archives.
This also lines up with https://github.com/adamhathcock/sharpcompress/issues/203#issuecomment-1117164160 , where it was suggested that the most reliable way to check for password protection is to check the entry anyways.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.