Browse Source

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

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

4
pyi2phosts/lib/utils.py

@ -56,7 +56,11 @@ def validate_config(config): @@ -56,7 +56,11 @@ def validate_config(config):
def get_b32(dest):
""" Calculate base32 hash from base64 """
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

Loading…
Cancel
Save