1
0
mirror of https://github.com/r4sas/py-i2phosts synced 2025-01-22 12:34:17 +00:00

utils.py: get_b32(): handle bad base64 hashes

This commit is contained in:
Hidden Z 2010-11-07 20:46:25 +00:00
parent 29129ab2f2
commit d017333906

View File

@ -56,7 +56,11 @@ def validate_config(config):
def get_b32(dest):
""" Calculate base32 hash from base64 """
raw_key = base64.b64decode(dest.encode('utf-8'), '-~')
hash = hashlib.sha256(raw_key)
b32 = base64.b32encode(hash.digest()).lower().replace('=', '')+'.b32.i2p'
return b32
try:
raw_key = base64.b64decode(dest.encode('utf-8'), '-~')
except TypeError:
return 'corrupted_base64_hash'
else:
hash = hashlib.sha256(raw_key)
b32 = base64.b32encode(hash.digest()).lower().replace('=', '')+'.b32.i2p'
return b32