fix #4093
This commit is contained in:
@@ -408,7 +408,10 @@ def base_decode(v, length, base):
|
|||||||
chars = __b43chars
|
chars = __b43chars
|
||||||
long_value = 0
|
long_value = 0
|
||||||
for (i, c) in enumerate(v[::-1]):
|
for (i, c) in enumerate(v[::-1]):
|
||||||
long_value += chars.find(bytes([c])) * (base**i)
|
digit = chars.find(bytes([c]))
|
||||||
|
if digit == -1:
|
||||||
|
raise ValueError('Forbidden character {} for base {}'.format(c, base))
|
||||||
|
long_value += digit * (base**i)
|
||||||
result = bytearray()
|
result = bytearray()
|
||||||
while long_value >= 256:
|
while long_value >= 256:
|
||||||
div, mod = divmod(long_value, 256)
|
div, mod = divmod(long_value, 256)
|
||||||
@@ -428,6 +431,10 @@ def base_decode(v, length, base):
|
|||||||
return bytes(result)
|
return bytes(result)
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidChecksum(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def EncodeBase58Check(vchIn):
|
def EncodeBase58Check(vchIn):
|
||||||
hash = Hash(vchIn)
|
hash = Hash(vchIn)
|
||||||
return base_encode(vchIn + hash[0:4], base=58)
|
return base_encode(vchIn + hash[0:4], base=58)
|
||||||
@@ -440,7 +447,7 @@ def DecodeBase58Check(psz):
|
|||||||
hash = Hash(key)
|
hash = Hash(key)
|
||||||
cs32 = hash[0:4]
|
cs32 = hash[0:4]
|
||||||
if cs32 != csum:
|
if cs32 != csum:
|
||||||
return None
|
raise InvalidChecksum('expected {}, actual {}'.format(bh2u(cs32), bh2u(csum)))
|
||||||
else:
|
else:
|
||||||
return key
|
return key
|
||||||
|
|
||||||
@@ -479,8 +486,9 @@ def deserialize_privkey(key):
|
|||||||
if ':' in key:
|
if ':' in key:
|
||||||
txin_type, key = key.split(sep=':', maxsplit=1)
|
txin_type, key = key.split(sep=':', maxsplit=1)
|
||||||
assert txin_type in SCRIPT_TYPES
|
assert txin_type in SCRIPT_TYPES
|
||||||
vch = DecodeBase58Check(key)
|
try:
|
||||||
if not vch:
|
vch = DecodeBase58Check(key)
|
||||||
|
except BaseException:
|
||||||
neutered_privkey = str(key)[:3] + '..' + str(key)[-2:]
|
neutered_privkey = str(key)[:3] + '..' + str(key)[-2:]
|
||||||
raise BaseException("cannot deserialize", neutered_privkey)
|
raise BaseException("cannot deserialize", neutered_privkey)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user