use baseconv.{to,from}bytes() wherever feasible
- also fixes a padding bug in the b58tobytes() tool method
This commit is contained in:
parent
9cc0777f54
commit
ca994bdd74
3 changed files with 9 additions and 9 deletions
|
|
@ -170,10 +170,10 @@ class AddrGeneratorMonero(AddrGenerator):
|
|||
return AddrGenerator.__init__(addr_type)
|
||||
|
||||
def b58enc(self,addr_bytes):
|
||||
enc = baseconv.fromhex
|
||||
enc = baseconv.frombytes
|
||||
l = len(addr_bytes)
|
||||
a = ''.join([enc((addr_bytes[i*8:i*8+8]).hex(),'b58',pad=11,tostr=True) for i in range(l//8)])
|
||||
b = enc((addr_bytes[l-l%8:]).hex(),'b58',pad=7,tostr=True)
|
||||
a = ''.join([enc(addr_bytes[i*8:i*8+8],'b58',pad=11,tostr=True) for i in range(l//8)])
|
||||
b = enc(addr_bytes[l-l%8:],'b58',pad=7,tostr=True)
|
||||
return a + b
|
||||
|
||||
def to_addr(self,sk_hex): # sk_hex instead of pubhex
|
||||
|
|
@ -923,7 +923,7 @@ Record this checksum: it will be used to verify the password file in the future
|
|||
elif pf in ('b32','b58'):
|
||||
pw_int = (32 if pf == 'b32' else 58) ** self.pw_len
|
||||
pw_bytes = pw_int.bit_length() // 8
|
||||
good_pw_len = len(baseconv.fromhex('ff'*seed.byte_len,wl_id=pf))
|
||||
good_pw_len = len(baseconv.frombytes(b'\xff'*seed.byte_len,wl_id=pf))
|
||||
else:
|
||||
raise NotImplementedError('{!r}: unknown password format'.format(pf))
|
||||
|
||||
|
|
|
|||
|
|
@ -321,11 +321,11 @@ class MMGenToolCmdUtil(MMGenToolCmdBase):
|
|||
def bytestob58(self,infile:str,pad=0):
|
||||
"convert bytes to base 58 (supply data via STDIN)"
|
||||
data = get_data_from_file(infile,dash=True,quiet=True,binary=True)
|
||||
return baseconv.fromhex(data.hex(),'b58',pad=pad,tostr=True)
|
||||
return baseconv.frombytes(data,'b58',pad=pad,tostr=True)
|
||||
|
||||
def b58tobytes(self,b58num:'sstr',pad=0):
|
||||
"convert a base 58 number to bytes (warning: outputs binary data)"
|
||||
return bytes.fromhex(baseconv.tohex(b58num,'b58',pad=pad))
|
||||
return baseconv.tobytes(b58num,'b58',pad=pad)
|
||||
|
||||
def hextob58(self,hexstr:'sstr',pad=0):
|
||||
"convert a hexadecimal number to base 58"
|
||||
|
|
|
|||
|
|
@ -204,9 +204,9 @@ tests = {
|
|||
( ['6h8cQN'], b'\xde\xad\xbe\xef' ),
|
||||
( ['eFGDJURJykA'], b'\xde\xad\xbe\xef\xde\xad\xbe\xef' ),
|
||||
( ['jpXCZedGfVQ'], b'\xff\xff\xff\xff\xff\xff\xff\xff' ),
|
||||
( ['1','pad=16'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
|
||||
( ['1111111111','pad=16'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
|
||||
( ['111111115Q','pad=2'], b'\xff' ),
|
||||
( ['1','pad=8'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
|
||||
( ['1111111111','pad=8'], b'\x00\x00\x00\x00\x00\x00\x00\x00' ),
|
||||
( ['111111115Q','pad=1'], b'\xff' ),
|
||||
],
|
||||
'hextob58': [
|
||||
( ['deadbeef'], '6h8cQN' ),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue