mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-03 21:00:48 +00:00
util: base32: require str-not-unicode inputs -- effectively rolls back [3306] and [3307]
This commit is contained in:
parent
c35a6ee3a2
commit
d4a5f9131b
@ -179,17 +179,13 @@ def init_s5():
|
|||||||
s5 = init_s5()
|
s5 = init_s5()
|
||||||
|
|
||||||
def could_be_base32_encoded(s, s8=s8, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
|
def could_be_base32_encoded(s, s8=s8, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
|
||||||
precondition(isinstance(s, (str, unicode)), s)
|
precondition(isinstance(s, str), s)
|
||||||
if isinstance(s, unicode):
|
|
||||||
s = s.encode('utf-8')
|
|
||||||
if s == '':
|
if s == '':
|
||||||
return True
|
return True
|
||||||
return s8[len(s)%8][ord(s[-1])] and not tr(s, identitytranstable, chars)
|
return s8[len(s)%8][ord(s[-1])] and not tr(s, identitytranstable, chars)
|
||||||
|
|
||||||
def could_be_base32_encoded_l(s, lengthinbits, s5=s5, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
|
def could_be_base32_encoded_l(s, lengthinbits, s5=s5, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
|
||||||
precondition(isinstance(s, (str, unicode)), s)
|
precondition(isinstance(s, str), s)
|
||||||
if isinstance(s, unicode):
|
|
||||||
s = s.encode('utf-8')
|
|
||||||
if s == '':
|
if s == '':
|
||||||
return True
|
return True
|
||||||
assert lengthinbits%5 < len(s5), lengthinbits
|
assert lengthinbits%5 < len(s5), lengthinbits
|
||||||
@ -205,9 +201,7 @@ def a2b(cs):
|
|||||||
@param cs the base-32 encoded data (a string)
|
@param cs the base-32 encoded data (a string)
|
||||||
"""
|
"""
|
||||||
precondition(could_be_base32_encoded(cs), "cs is required to be possibly base32 encoded data.", cs=cs)
|
precondition(could_be_base32_encoded(cs), "cs is required to be possibly base32 encoded data.", cs=cs)
|
||||||
precondition(isinstance(cs, (str, unicode)), cs)
|
precondition(isinstance(cs, str), cs)
|
||||||
if isinstance(cs, unicode):
|
|
||||||
cs = cs.encode('utf-8')
|
|
||||||
|
|
||||||
return a2b_l(cs, num_octets_that_encode_to_this_many_quintets(len(cs))*8)
|
return a2b_l(cs, num_octets_that_encode_to_this_many_quintets(len(cs))*8)
|
||||||
|
|
||||||
@ -232,9 +226,7 @@ def a2b_l(cs, lengthinbits):
|
|||||||
@return the data encoded in cs
|
@return the data encoded in cs
|
||||||
"""
|
"""
|
||||||
precondition(could_be_base32_encoded_l(cs, lengthinbits), "cs is required to be possibly base32 encoded data.", cs=cs, lengthinbits=lengthinbits)
|
precondition(could_be_base32_encoded_l(cs, lengthinbits), "cs is required to be possibly base32 encoded data.", cs=cs, lengthinbits=lengthinbits)
|
||||||
precondition(isinstance(cs, (str, unicode)), cs)
|
precondition(isinstance(cs, str), cs)
|
||||||
if isinstance(cs, unicode):
|
|
||||||
cs = cs.encode('utf-8')
|
|
||||||
if cs == '':
|
if cs == '':
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user