def calc(name, qtype): start_time = time.perf_counter() key = name + qtype d_id = hashing(name.encode()).hexdigest()[:28] c_id = hashing(key.encode()).hexdigest() end_time = time.perf_counter() calc_time = end_time - start_time return calc_time
def hash_file(file, directory=''): hasher = hashing() with open(directory + '\\' + file, 'rb') as afile: buf = afile.read(64) while len(buf) > 0: hasher.update(buf) buf = afile.read(64) # return hasher.digest() return hasher.hexdigest()
def _addToCache(self, tp: str, data: dict, *args): self._loadCache() key = hashing( (str(tp) + ":" + ",".join(str(i) for i in args)).encode('utf-8')).hexdigest() if tp not in self._data: self._data[tp] = {key: {"date": time.time(), "data": data}} else: self._data[tp][key] = {"date": time.time(), "data": data} self._save()
def _get(self, tp: str, *args, getAnyway: bool = False): self._loadCache() key = hashing( (str(tp) + ":" + ",".join(str(i) for i in args)).encode('utf-8')).hexdigest() if tp not in self._data: return None else: if key in self._data[tp]: if getAnyway: return self._data[tp][key]['data'] if self._validateDate(self._data[tp][key]['date'], time.time()): return self._data[tp][key]['data'] else: # del self._data[tp][key] # self._save() return True else: return False
def valid_token(token, login, type): """Validate a security token. Type can be 'validate_email' or 'resetpwd' """ conf = ConfReader('hedgehog.ini') s = str(conf.salt) + login + type return hashing(s).hexdigest() == token
def calc(self, name, qtype): key = name + qtype d_id = hashing(name.encode()).hexdigest()[:2] c_id = hashing(key.encode()).hexdigest() return d_id, c_id