kopia lustrzana https://github.com/bellingcat/auto-archiver
fixes bad hash initialization
rodzic
15abf686b1
commit
ab6cf52533
|
@ -30,10 +30,10 @@ class HashEnricher(Enricher):
|
||||||
to_enrich.media[i].set("hash", f"{self.algorithm}:{hd}")
|
to_enrich.media[i].set("hash", f"{self.algorithm}:{hd}")
|
||||||
|
|
||||||
def calculate_hash(self, filename) -> str:
|
def calculate_hash(self, filename) -> str:
|
||||||
hash = None
|
hash_algo = None
|
||||||
if self.algorithm == "SHA-256":
|
if self.algorithm == "SHA-256":
|
||||||
hash = hashlib.sha256()
|
hash_algo = hashlib.sha256
|
||||||
elif self.algorithm == "SHA3-512":
|
elif self.algorithm == "SHA3-512":
|
||||||
hash = hashlib.sha3_512()
|
hash_algo = hashlib.sha3_512
|
||||||
else: return ""
|
else: return ""
|
||||||
return calculate_file_hash(filename, hash, self.chunksize)
|
return calculate_file_hash(filename, hash_algo, self.chunksize)
|
||||||
|
|
|
@ -65,10 +65,11 @@ def json_loader(cli_val):
|
||||||
return json.loads(cli_val)
|
return json.loads(cli_val)
|
||||||
|
|
||||||
|
|
||||||
def calculate_file_hash(filename: str, hash_algo = hashlib.sha256(), chunksize: int = 16000000) -> str:
|
def calculate_file_hash(filename: str, hash_algo = hashlib.sha256, chunksize: int = 16000000) -> str:
|
||||||
|
hash = hash_algo()
|
||||||
with open(filename, "rb") as f:
|
with open(filename, "rb") as f:
|
||||||
while True:
|
while True:
|
||||||
buf = f.read(chunksize)
|
buf = f.read(chunksize)
|
||||||
if not buf: break
|
if not buf: break
|
||||||
hash_algo.update(buf)
|
hash.update(buf)
|
||||||
return hash_algo.hexdigest()
|
return hash.hexdigest()
|
||||||
|
|
Ładowanie…
Reference in New Issue