FileHashingWrapper: support and use sha256

Cryptographically strong and often hw accelerated nowadays.

Also support by borgstore hash method.
This commit is contained in:
Thomas Waldmann 2026-05-28 18:51:01 +02:00
parent 9389d98c6d
commit 53b48f0940
No known key found for this signature in database
GPG key ID: 243ACFA951F78E01

View file

@ -5,8 +5,6 @@ from hmac import compare_digest
from collections.abc import Callable
from pathlib import Path
from xxhash import xxh64
from ..helpers import IntegrityError
from ..logger import create_logger
@ -106,20 +104,12 @@ class FileHashingWrapper(FileLikeWrapper):
self.hash.update(str(self.tell()).encode())
class SHA512FileHashingWrapper(FileHashingWrapper):
ALGORITHM = "SHA512"
FACTORY = hashlib.sha512
class SHA256FileHashingWrapper(FileHashingWrapper):
ALGORITHM = "SHA256"
FACTORY = hashlib.sha256
class XXH64FileHashingWrapper(FileHashingWrapper):
ALGORITHM = "XXH64"
FACTORY = xxh64
SUPPORTED_ALGORITHMS = {
SHA512FileHashingWrapper.ALGORITHM: SHA512FileHashingWrapper,
XXH64FileHashingWrapper.ALGORITHM: XXH64FileHashingWrapper,
}
SUPPORTED_ALGORITHMS = {SHA256FileHashingWrapper.ALGORITHM: SHA256FileHashingWrapper}
class FileIntegrityError(IntegrityError):
@ -137,7 +127,7 @@ class IntegrityCheckedFile(FileLikeWrapper):
self.file_opened = override_fd is None
self.digests = {}
hash_cls = XXH64FileHashingWrapper
hash_cls = SHA256FileHashingWrapper
if not write:
algorithm_and_digests = self.load_integrity_data(path, integrity_data)