Skip to content

Commit

Permalink
Merge branch 'master' into topic-digest-check
Browse files Browse the repository at this point in the history
  • Loading branch information
miurahr authored Jun 3, 2020
2 parents 2eb1b99 + 7b801d3 commit 7177a1d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ All notable changes to this project will be documented in this file.
Added
-----

* Support for encrypted header (#139, #140)

Changed
-------

Fixed
-----

* Allow decryption of data which is encrypted without any compression.(#140)

Deprecated
----------

Expand Down
3 changes: 0 additions & 3 deletions py7zr/archiveinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,6 @@ def _get_headerdata_from_streams(self, fp: BinaryIO, streams: StreamsInfo) -> By
buffer = io.BytesIO()
src_start = self._start_pos
for folder in streams.unpackinfo.folders:
if folder.is_encrypted():
raise UnsupportedCompressionMethodError()

uncompressed = folder.unpacksizes
if not isinstance(uncompressed, (list, tuple)):
uncompressed = [uncompressed] * len(folder.coders)
Expand Down
5 changes: 4 additions & 1 deletion py7zr/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ def __init__(self, aes_properties: bytes, password: str, coders: List[Dict[str,
if ivsize < 16:
iv += bytes('\x00' * (16 - ivsize), 'ascii')
key = calculate_key(byte_password, numcyclespower, salt, 'sha256')
self.lzma_decompressor = self._set_lzma_decompressor(coders) # type: lzma.LZMADecompressor
if len(coders) > 0:
self.lzma_decompressor = self._set_lzma_decompressor(coders) # type: lzma.LZMADecompressor
else:
self.lzma_decompressor = CopyDecompressor()
self.cipher = AES.new(key, AES.MODE_CBC, iv)
self.buf = Buffer(size=READ_BLOCKSIZE + 16)
self.flushed = False
Expand Down
Binary file added tests/data/filename_encryption.7z
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,10 @@ def test_archivetest_lzma_bcj_sparc():
def test_archivetest_7zaes():
with py7zr.SevenZipFile(os.path.join(testdata_path, 'encrypted_1.7z'), 'r', password='secret') as ar:
assert ar.testzip() is None


@pytest.mark.files
def test_list_filename_encryption(tmp_path):
with py7zr.SevenZipFile(os.path.join(testdata_path, 'filename_encryption.7z'), 'r', password='hello') as ar:
file_list = ar.list()
assert file_list[0].filename == "New Text Document.TXT"

0 comments on commit 7177a1d

Please sign in to comment.