[PR #1060] [MERGED] Add archive-level password protection flags for 7z and rar #1488

Closed
opened 2026-01-29 22:20:48 +00:00 by claunia · 0 comments
Owner

📋 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: masterHead: rar-7z-password


📝 Commits (4)

📊 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.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1060 **Author:** [@HeroponRikiBestest](https://github.com/HeroponRikiBestest) **Created:** 12/2/2025 **Status:** ✅ Merged **Merged:** 12/3/2025 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `master` ← **Head:** `rar-7z-password` --- ### 📝 Commits (4) - [`99a6c4d`](https://github.com/adamhathcock/sharpcompress/commit/99a6c4de886593077159219289a94bf18306435a) Add archive-level IsEncrypted flag - [`e0660e7`](https://github.com/adamhathcock/sharpcompress/commit/e0660e777534b94afc89d59fde934c1cc90ae887) Add tests - [`1b1df86`](https://github.com/adamhathcock/sharpcompress/commit/1b1df86a114e57067150aab9931ad25255cd082e) Improve logic - [`41c3cc1`](https://github.com/adamhathcock/sharpcompress/commit/41c3cc1a18cde27b2744ac6e9724543b52a1bbf6) Csharpier ### 📊 Changes **6 files changed** (+27 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `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) </details> ### 📄 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:20:48 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1488