From c1ba807502d188db0fe07594e9d372f7e63932b0 Mon Sep 17 00:00:00 2001 From: MMGen Date: Fri, 18 Oct 2019 16:59:24 +0000 Subject: [PATCH] MMGenPasswordType: initialize all unused fields with 'None' --- mmgen/addr.py | 1 + mmgen/obj.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mmgen/addr.py b/mmgen/addr.py index ee99fd8c..5df86c1b 100755 --- a/mmgen/addr.py +++ b/mmgen/addr.py @@ -311,6 +311,7 @@ class AddrListChksum(str,Hilite): def __new__(cls,addrlist): ea = addrlist.al_id.mmtype.extra_attrs # add viewkey and passwd to the mix, if present + if ea == None: ea = () lines = [' '.join( addrlist.chksum_rec_f(e) + tuple(getattr(e,a) for a in ea if getattr(e,a)) diff --git a/mmgen/obj.py b/mmgen/obj.py index 68297a29..6587c705 100755 --- a/mmgen/obj.py +++ b/mmgen/obj.py @@ -732,17 +732,17 @@ class PrivKey(str,Hilite,InitErrors,MMGenObject): return cls.init_fail(e,s,objname='{} WIF key'.format(g.coin)) else: try: - assert s,'private key hex data missing' - assert compressed is not None, "'compressed' arg missing" + assert s,'private key bin data missing' assert pubkey_type is not None,"'pubkey_type' arg missing" - assert type(compressed) == bool,"{!r}: 'compressed' not of type 'bool'".format(compressed) assert len(s) == cls.width // 2,'key length must be {}'.format(cls.width // 2) if pubkey_type == 'password': # skip WIF creation and pre-processing for passwds me = str.__new__(cls,s.hex()) else: + assert compressed is not None, "'compressed' arg missing" + assert type(compressed) == bool,"{!r}: 'compressed' not of type 'bool'".format(compressed) me = str.__new__(cls,g.proto.preprocess_key(s.hex(),pubkey_type)) me.wif = WifKey(g.proto.hex2wif(me,pubkey_type,compressed),on_fail='raise') - me.compressed = compressed + me.compressed = compressed me.pubkey_type = pubkey_type me.orig_hex = s.hex() # save the non-preprocessed key return me @@ -858,11 +858,11 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject): name = MMGenImmutableAttr('name',str) pubkey_type = MMGenImmutableAttr('pubkey_type',str) - compressed = MMGenImmutableAttr('compressed',bool) - gen_method = MMGenImmutableAttr('gen_method',str) - addr_fmt = MMGenImmutableAttr('addr_fmt',str) - wif_label = MMGenImmutableAttr('wif_label',str) - extra_attrs = MMGenImmutableAttr('extra_attrs',tuple) + compressed = MMGenImmutableAttr('compressed',bool,set_none_ok=True) + gen_method = MMGenImmutableAttr('gen_method',str,set_none_ok=True) + addr_fmt = MMGenImmutableAttr('addr_fmt',str,set_none_ok=True) + wif_label = MMGenImmutableAttr('wif_label',str,set_none_ok=True) + extra_attrs = MMGenImmutableAttr('extra_attrs',tuple,set_none_ok=True) desc = MMGenImmutableAttr('desc',str) mmtypes = { @@ -900,5 +900,5 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject): class MMGenPasswordType(MMGenAddrType): mmtypes = { - 'P': ati('password', 'password', False, None, None, None, (), 'Password generated from MMGen seed') + 'P': ati('password', 'password', None, None, None, None, None, 'Password generated from MMGen seed') }