Skip to content

Commit

Permalink
Merge branch 'master' into topic/miurahr/performance/drop-manual-gc-c…
Browse files Browse the repository at this point in the history
…all-issue-489
  • Loading branch information
miurahr committed Nov 5, 2022
2 parents 38991e7 + c87f19c commit 70bc5de
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 131 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
max-line-length = 125
extend-ignore = E203, W503
ignore = F841
4 changes: 2 additions & 2 deletions .github/workflows/run-benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
python-version: ['3.10', 'pypy3.7']
python-version: ['3.11', 'pypy-3.9']
name: Benchmark on Python ${{ matrix.python-version }}
env:
ISSUE_NUMBER: 297
Expand Down
27 changes: 11 additions & 16 deletions .github/workflows/run-tox-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,24 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
os: [ubuntu-22.04, windows-latest]
python-version: [
"3.7",
"3.8",
"3.9",
"3.10",
"3.11-dev",
"pypy3.7",
"3.11",
"pypy-3.9",
]
include:
- os: macos-latest
python-version: "3.10"
python-version: "3.11"
exclude:
- os: windows-latest
python-version: pypy3.7
python-version: 'pypy-3.9'
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 20
- name: Setup python
Expand Down Expand Up @@ -89,15 +89,15 @@ jobs:

test_slow_tests:
name: Test slow test cases
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 20
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: '3.11'
architecture: x64
- name: Install system library(linux)
run: |
Expand All @@ -114,14 +114,14 @@ jobs:

test_on_aarch64:
name: Test on ${{ matrix.arch }}
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [aarch64]
distro: [ubuntu20.04]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 20
- uses: uraimo/[email protected]
Expand All @@ -147,11 +147,6 @@ jobs:
needs: build
if: github.ref == 'refs/heads/master'
steps:
- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.8
architecture: x64
- name: Tell Coveralls that the parallel build is finished
run: |
curl -k \
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include *.rst
include *.svg
include *.toml
include .flake8
include LICENSE
include py7zr/py.typed
recursive-include py7zr *.py
Expand Down
23 changes: 12 additions & 11 deletions py7zr/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#
#
import ctypes
import hashlib
import os
import pathlib
import platform
Expand All @@ -30,8 +31,6 @@
from datetime import datetime, timedelta, timezone, tzinfo
from typing import BinaryIO, List, Optional, Union

import _hashlib # type: ignore # noqa

import py7zr.win32compat
from py7zr import Bad7zFile
from py7zr.win32compat import is_windows_native_python, is_windows_unc_path
Expand All @@ -54,17 +53,23 @@ def calculate_crc32(data: bytes, value: int = 0, blocksize: int = 1024 * 1024) -
return value & 0xFFFFFFFF


def _get_hash(digest: str):
if digest not in hashlib.algorithms_available:
raise ValueError("Unknown digest method for password protection.")
if digest == "sha256":
return hashlib.sha256()
return hashlib.new(digest)


def _calculate_key1(password: bytes, cycles: int, salt: bytes, digest: str) -> bytes:
"""Calculate 7zip AES encryption key. Base implementation."""
if digest not in ("sha256"):
raise ValueError("Unknown digest method for password protection.")
assert cycles <= 0x3F
if cycles == 0x3F:
ba = bytearray(salt + password + bytes(32))
key: bytes = bytes(ba[:32])
else:
rounds = 1 << cycles
m = _hashlib.new(digest)
m = _get_hash(digest)
for round in range(rounds):
m.update(salt + password + round.to_bytes(8, byteorder="little", signed=False))
key = m.digest()[:32]
Expand All @@ -74,14 +79,12 @@ def _calculate_key1(password: bytes, cycles: int, salt: bytes, digest: str) -> b
def _calculate_key2(password: bytes, cycles: int, salt: bytes, digest: str):
"""Calculate 7zip AES encryption key.
It uses ctypes and memoryview buffer and zero-copy technology on Python."""
if digest not in ("sha256"):
raise ValueError("Unknown digest method for password protection.")
assert cycles <= 0x3F
if cycles == 0x3F:
key: bytes = bytes(bytearray(salt + password + bytes(32))[:32])
else:
rounds = 1 << cycles
m = _hashlib.new(digest)
m = _get_hash(digest)
length = len(salt) + len(password)

class RoundBuf(ctypes.LittleEndianStructure):
Expand All @@ -106,8 +109,6 @@ class RoundBuf(ctypes.LittleEndianStructure):
def _calculate_key3(password: bytes, cycles: int, salt: bytes, digest: str) -> bytes:
"""Calculate 7zip AES encryption key.
Concat values in order to reduce number of calls of Hash.update()."""
if digest not in ("sha256"):
raise ValueError("Unknown digest method for password protection.")
assert cycles <= 0x3F
if cycles == 0x3F:
ba = bytearray(salt + password + bytes(32))
Expand All @@ -120,7 +121,7 @@ def _calculate_key3(password: bytes, cycles: int, salt: bytes, digest: str) -> b
else:
rounds = 1 << cycles
stages = 1 << 0
m = _hashlib.new(digest)
m = _get_hash(digest)
saltpassword = salt + password
s = 0 # type: int # (0..stages) * rounds
if platform.python_implementation() == "PyPy":
Expand Down
18 changes: 13 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
name = "py7zr"
requires-python = ">=3.7"
description = "Pure python 7-zip library"
readme = "README.rst"
license = {text = "LGPL-2.1-or-later"}
authors = [
{name = "Hiroshi Miura", email = "[email protected]"},
Expand Down Expand Up @@ -40,7 +39,16 @@ dependencies = [
'inflate64>=0.3.1;python_version>"3.6"',
]
keywords = ['compression', '7zip', 'lzma', 'zstandard', 'ppmd', 'lzma2', 'bcj', 'archive']
dynamic = ["version", "entry-points"]
dynamic = ["readme", "version"]

[tool.setuptools]
packages = ["py7zr"]

[tool.setuptools.package-data]
py7zr = ["py.typed"]

[tool.setuptools.dynamic]
readme = {file = ["README.rst"]}

[project.scripts]
py7zr = "py7zr.__main__:main"
Expand Down Expand Up @@ -156,15 +164,15 @@ markers = [
legacy_tox_ini = """
[tox]
isolated_build = True
envlist = mypy, check, pypy{37,38}, py{37,38,39,310,311}, py39d, docs, mprof
envlist = mypy, check, pypy{37,38,39}, py{37,38,39,310,311}, py39d, docs, mprof
[testenv]
passenv = GITHUB_* PYTEST_ADDOPTS COVERALLS_* LIBARCHIVE
extras = test
commands =
python -m pytest -vv
depends =
pypy3,py{36,37,38,39,310}: clean, check
pypy{37,38,39},py{36,37,38,39,310}: clean, check
[testenv:py38]
extras = test, test_compat
Expand Down Expand Up @@ -228,5 +236,5 @@ python =
3.9: py39
3.10: py310
3.11: py311
pypy3.7: pypy37
pypy-3.9: pypy39
"""
97 changes: 0 additions & 97 deletions setup.cfg

This file was deleted.

0 comments on commit 70bc5de

Please sign in to comment.