From 82c32c2a0b7d262848c231563eed5255b15670e4 Mon Sep 17 00:00:00 2001 From: Timothy Farrell Date: Mon, 9 Mar 2026 09:36:57 +0000 Subject: [PATCH] Add deterministic hash salt. --- main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index a96819b..4bed5c7 100644 --- a/main.py +++ b/main.py @@ -16,16 +16,16 @@ indexer = None class FileIndexer: - def __init__(self, path: str): + def __init__(self, path: str, salt: str | None = None): self.path = Path(path) self.file_mapping = {} - self._salt = None + self._salt = salt self._index() @property def salt(self) -> str: """Generate a random salt for hashing""" - if not self._salt: + if self._salt is None: self._salt = secrets.token_hex(16) return self._salt @@ -97,7 +97,11 @@ def initialize_server(args: argparse.Namespace): if not src_path.exists(): raise SystemExit(f"Source path {src_path} does not exist") - indexer = FileIndexer(src_path) if src_path.is_dir() else INDEXER_MAP[src_path.suffix](src_path) + indexer = ( + FileIndexer(src_path, args.salt) + if src_path.is_dir() + else INDEXER_MAP[src_path.suffix](src_path, args.salt) + ) print(f"Indexed {len(indexer.file_mapping)} files") @@ -167,6 +171,7 @@ if __name__ == "__main__": parser.add_argument("source", type=str, help="Path to directory or ZIP archive") parser.add_argument("--host", type=str, default="0.0.0.0", help="Host to bind to") parser.add_argument("--port", type=int, default=8000, help="Port to bind to") + parser.add_argument("--salt", type=str, default=None, help="Salt for hashing file paths") args = parser.parse_args() initialize_server(args)