Browse Source

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

pull/1/head
Hidden Z 14 years ago
parent
commit
d017333906
  1. 12
      pyi2phosts/lib/utils.py

12
pyi2phosts/lib/utils.py

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

Loading…
Cancel
Save