diff --git a/voussoirkit/spinal.py b/voussoirkit/spinal.py index 04519ab..b1d225d 100644 --- a/voussoirkit/spinal.py +++ b/voussoirkit/spinal.py @@ -539,7 +539,13 @@ def normalize(text): ''' return os.path.normpath(os.path.normcase(text)) -def verify_hash(path, known_size, known_hash, callback=None): +def verify_hash( + path, + known_hash, + *, + known_size=None, + callback=None, + ): ''' callback: A function that takes three parameters: @@ -563,6 +569,11 @@ def verify_hash(path, known_size, known_hash, callback=None): if callback is not None: callback(path, checked_bytes, file_size) + if known_size is not None: + file_size = os.path.getsize(path.absolute_path) + if file_size != known_size: + raise ValidationError(f'File size {file_size} != known size {known_size}.') + file_hash = hasher.hexdigest() if file_hash != known_hash: raise ValidationError(f'File hash "{file_hash}" != known hash "{known_hash}".')