die roll wallet: handle invalid data length, add base6d tool cmds
This commit is contained in:
parent
99d968e4aa
commit
ac48947769
4 changed files with 56 additions and 4 deletions
|
|
@ -1045,10 +1045,15 @@ class DieRollSeedFile(SeedSourceUnenc):
|
|||
|
||||
def _deformat(self):
|
||||
|
||||
d = self.fmt_data.translate(dict((ord(ws),None) for ws in '\t\n '))
|
||||
d = remove_whitespace(self.fmt_data)
|
||||
|
||||
rmap = self.conv_cls.seedlen_map_rev['b6d']
|
||||
if not len(d) in rmap:
|
||||
m = '{!r}: invalid length for {} (must be one of {})'
|
||||
raise SeedLengthError(m.format(len(d),self.desc,list(rmap)))
|
||||
|
||||
# truncate seed to correct length, discarding high bits
|
||||
seed_len = self.conv_cls.seedlen_map_rev['b6d'][len(d)]
|
||||
seed_len = rmap[len(d)]
|
||||
seed_bytes = baseconv.tobytes(d,'b6d',pad='seed')[-seed_len:]
|
||||
|
||||
if self.interactive_input and opt.usr_randchars:
|
||||
|
|
|
|||
|
|
@ -355,6 +355,15 @@ class MMGenToolCmdUtil(MMGenToolCmdBase):
|
|||
"convert an MMGen-flavor base 32 number to hexadecimal"
|
||||
return baseconv.tohex(b32num.upper(),'b32',pad)
|
||||
|
||||
def hextob6d(self,hexstr:'sstr',pad=0,add_spaces=True):
|
||||
"convert a hexadecimal number to die roll base6 (base6d)"
|
||||
ret = baseconv.fromhex(hexstr,'b6d',pad,tostr=True)
|
||||
return block_format(ret,gw=5,cols=None).strip() if add_spaces else ret
|
||||
|
||||
def b6dtohex(self,b6d_num:'sstr',pad=0):
|
||||
"convert a die roll base6 (base6d) number to hexadecimal"
|
||||
return baseconv.tohex(remove_whitespace(b6d_num),'b6d',pad)
|
||||
|
||||
class MMGenToolCmdCoin(MMGenToolCmdBase):
|
||||
"""
|
||||
cryptocoin key/address utilities
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared):
|
|||
# ('txcreate8', 'transaction creation (8)'),
|
||||
('ref_tx_chk', 'signing saved reference tx file'),
|
||||
('ref_brain_chk_spc3', 'saved brainwallet (non-standard spacing)'),
|
||||
('ref_dieroll_chk_overflow','saved dieroll wallet with extra entropy bits'),
|
||||
('ref_dieroll_chk_seedtruncate','saved dieroll wallet with extra entropy bits'),
|
||||
('ref_tool_decrypt', 'decryption of saved MMGen-encrypted file'),
|
||||
)
|
||||
|
||||
|
|
@ -266,7 +266,7 @@ class TestSuiteRef(TestSuiteBase,TestSuiteShared):
|
|||
def ref_brain_chk_spc3(self):
|
||||
return self.ref_brain_chk(bw_file=ref_bw_file_spc)
|
||||
|
||||
def ref_dieroll_chk_overflow(self):
|
||||
def ref_dieroll_chk_seedtruncate(self):
|
||||
wf = joinpath(ref_dir,'overflow128.b6d')
|
||||
return self.walletchk(wf,None,sid='8EC6D4A2')
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,44 @@ tests = {
|
|||
( ['AAAAAAAAAA','pad=16'], '0000000000000000' ),
|
||||
( ['AAAAAAAAH7','pad=2'], 'ff' ),
|
||||
],
|
||||
'hextob6d': [
|
||||
( ['deadbeef'], '25255 24636 426' ),
|
||||
( ['deadbeefdeadbeef'], '43263 51255 35545 36422 42642' ),
|
||||
( ['ffffffffffffffff'], '46316 33121 21321 15553 55534' ),
|
||||
( ['0000000000000000'], '1' ),
|
||||
( ['0000000000000000','pad=10'], '11111 11111' ),
|
||||
( ['ff','pad=10'], '11111 12214' ),
|
||||
( ['ff'*16],
|
||||
'34164 46464 12666 61652 46515 46546 53354 43666 45555 21414' ),
|
||||
( ['ff'*24],
|
||||
'24611 14114 33323 36422 24655 66552 32465 25661 21541 62342 '
|
||||
'61351 63525 45161 35543 13654' ),
|
||||
( ['ff'*32],
|
||||
'21325 21653 31261 31341 45131 42346 54146 36252 11413 12253 '
|
||||
'24246 31114 16424 56513 41632 24121 46151 43214 22425 65134' ),
|
||||
],
|
||||
'b6dtohex': [
|
||||
( ['25255 24636 426'], 'deadbeef' ),
|
||||
( ['43263 51255 35545 36422 42642'], 'deadbeefdeadbeef' ),
|
||||
( ['46316 33121 21321 15553 55534'], 'ffffffffffffffff' ),
|
||||
( ['1','pad=16'], '0000000000000000' ),
|
||||
( ['11111 11111','pad=16'], '0000000000000000' ),
|
||||
( ['11111 12214','pad=2'], 'ff' ),
|
||||
( ['22222 22222'], 'b88733' ),
|
||||
( ['66666 66666'], '039aa3ff' ),
|
||||
( ['6'*50], {
|
||||
'len': 34,
|
||||
'value':'0260154fc36cbf42778f23ffffffffffff' # 130 bits
|
||||
} ),
|
||||
( ['6'*75], {
|
||||
'len': 50,
|
||||
'value':'03a92ef1c3432e71a7679561bb6817d7ffffffffffffffffff' # 194 bits
|
||||
} ),
|
||||
( ['6'*100], {
|
||||
'len': 66,
|
||||
'value':'05a4653ca673768565b41f775d6947d55cf3813d0fffffffffffffffffffffffff' # 259 bits
|
||||
} ),
|
||||
],
|
||||
'hextob58chk': [
|
||||
( ['deadbeef'], 'eFGDJPketnz' ),
|
||||
( ['deadbeefdeadbeef'], '5CizhNNRPYpBjrbYX' ),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue