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

Source Code for Module lib.common.hashing

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