mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-30 17:56:58 +00:00
23 lines
543 B
Python
23 lines
543 B
Python
from base64 import b32encode, b32decode
|
|
|
|
def b2a(i):
|
|
assert isinstance(i, str), "tried to idlib.b2a non-string '%s'" % (i,)
|
|
return b32encode(i).lower()
|
|
|
|
def b2a_or_none(i):
|
|
if i is None:
|
|
return None
|
|
return b2a(i)
|
|
|
|
def a2b(i):
|
|
assert isinstance(i, str), "tried to idlib.a2b non-string '%s'" % (i,)
|
|
try:
|
|
return b32decode(i.upper())
|
|
except TypeError:
|
|
print "b32decode failed on a %s byte string '%s'" % (len(i), i)
|
|
raise
|
|
|
|
|
|
def peerid_to_short_string(peerid):
|
|
return b2a(peerid)[:4]
|