Package lib :: Package common :: Module hashing
[hide private]
[frames] | no frames]

Source Code for Module lib.common.hashing

 1  # Copyright (C) 2010-2013 Claudio Guarnieri. 
 2  # Copyright (C) 2014-2016 Cuckoo Foundation. 
 3  # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org 
 4  # See the file 'docs/LICENSE' for copying permission. 
 5   
 6  BUFSIZE = 1024*1024 
 7   
 8   
9 -def hash_file(method, path):
10 """Calculates an hash on a file by path. 11 @param method: callable hashing method 12 @param path: file path 13 @return: computed hash string 14 """ 15 f = open(path, "rb") 16 h = method() 17 while True: 18 buf = f.read(BUFSIZE) 19 if not buf: 20 break 21 h.update(buf) 22 return h.hexdigest()
23