diff options
| author | 2024-01-16 22:15:03 +0800 | |
|---|---|---|
| committer | 2024-01-16 22:15:03 +0800 | |
| commit | 2083e1648b34ea5b236313cff28b4fd49dad4951 (patch) | |
| tree | ffb58172add131326dccea9a3c891dae23958b91 /src | |
| parent | 23755e874b75f65f332cc00c3cc0c96da33dfb87 (diff) | |
| download | ipm-2083e1648b34ea5b236313cff28b4fd49dad4951.tar.gz ipm-2083e1648b34ea5b236313cff28b4fd49dad4951.zip | |
:recycle: chore(rename): rename hash function
Diffstat (limited to 'src')
| -rw-r--r-- | src/ipm/utils/freeze.py | 6 | ||||
| -rw-r--r-- | src/ipm/utils/hash.py | 6 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/ipm/utils/freeze.py b/src/ipm/utils/freeze.py index f03078f..8f7698f 100644 --- a/src/ipm/utils/freeze.py +++ b/src/ipm/utils/freeze.py @@ -2,7 +2,7 @@ from pathlib import Path from . import _freeze from ..exceptions import FileNotFoundError, VerifyFailed from ..models.ipk import InfiniPackage, InfiniFrozenPackage -from .hash import hash_ifp, verify_ifp +from .hash import ifp_hash, ifp_verify from ..typing import StrPath import tempfile @@ -31,7 +31,7 @@ def build_ipk(ipk: InfiniPackage) -> InfiniFrozenPackage: str(ifp_path), ) - (dist_path / ipk.hash_name).write_bytes(hash_ifp(ifp_path)) + (dist_path / ipk.hash_name).write_bytes(ifp_hash(ifp_path)) return InfiniFrozenPackage(source_path=ifp_path, **{"name": ipk.name}) @@ -44,7 +44,7 @@ def extract_ipk(source_path: StrPath, dist_path: str | Path) -> InfiniPackage: if not hash_path.exists(): raise VerifyFailed("哈希文件不存在!") - if not verify_ifp(ifp_path, hash_path.read_bytes()): + if not ifp_verify(ifp_path, hash_path.read_bytes()): raise VerifyFailed("文件完整性验证失败!") temp_dir = tempfile.TemporaryDirectory() diff --git a/src/ipm/utils/hash.py b/src/ipm/utils/hash.py index 54d5b13..c1fa37b 100644 --- a/src/ipm/utils/hash.py +++ b/src/ipm/utils/hash.py @@ -2,7 +2,7 @@ from pathlib import Path import hashlib -def hash_ifp(lfp_path: str | Path, block_size=65536) -> bytes: +def ifp_hash(lfp_path: str | Path, block_size=65536) -> bytes: sha256 = hashlib.sha256() with Path(lfp_path).resolve().open("rb") as file: for block in iter(lambda: file.read(block_size), b""): @@ -10,6 +10,6 @@ def hash_ifp(lfp_path: str | Path, block_size=65536) -> bytes: return sha256.digest() -def verify_ifp(lfp_path, expected_hash) -> bool: - actual_hash = hash_ifp(lfp_path) +def ifp_verify(lfp_path, expected_hash) -> bool: + actual_hash = ifp_hash(lfp_path) return actual_hash == expected_hash |
