mirror of
https://github.com/hanzoui/custom-nodes-security-scan.git
synced 2026-10-30 20:56:54 +00:00
23 lines
593 B
Python
23 lines
593 B
Python
# Copyright (C) 2010-2013 Claudio Guarnieri.
|
|
# Copyright (C) 2014-2016 Cuckoo Foundation.
|
|
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
|
|
# See the file 'docs/LICENSE' for copying permission.
|
|
|
|
BUFSIZE = 1024*1024
|
|
|
|
|
|
def hash_file(method, path):
|
|
"""Calculate a hash on a file by path.
|
|
@param method: callable hashing method
|
|
@param path: file path
|
|
@return: computed hash string
|
|
"""
|
|
f = open(path, "rb")
|
|
h = method()
|
|
while True:
|
|
buf = f.read(BUFSIZE)
|
|
if not buf:
|
|
break
|
|
h.update(buf)
|
|
return h.hexdigest()
|