def _encode_token(self, token):
"""
takes a token as input, if token is in encoding dictionary, looks its
hash up and returns it. else, hashes it, checks it for collisions
(overkill) while updating en(de)coding dictionaries.
:param token: str: token.
:return: str: hashed token
"""
if token in self.encode_dictionary:
return self.encode_dictionary[token]
else:
hashed_token, salt = hash_token(token,
hash_function=self.hash_function,
salt_length=self.salt_length,
salt=self.one_salt)
while hashed_token in self.decode_dictionary:
hashed_token, salt = hash_token(token,
hash_function=self.hash_function,
salt_length=self.salt_length,
salt=None)
self.decode_dictionary[hashed_token] = (token,
base64.b85encode(salt).decode())
self.encode_dictionary[token] = hashed_token
return hashed_token
评论列表
文章目录