@@ -96,15 +96,23 @@ def accountgroups_input(
9696 if not record :
9797 continue
9898
99- # See if records are indexed. Only int or 'nonce' is accepted for index.
99+ # See if records are indexed. Only int or 'nonce' is accepted for index. Ignore any
100+ # (strange) empty '<index>: ' records (anything possible w/ corruption on a serial link...)
100101 index = None
102+ payload = ''
101103 try :
102104 index ,payload = record .split ( ':' , 1 ) # ValueError if not <index>:<payload>
103105 index = int ( index ) # ValueError if <index> not int
104106 except ValueError :
105107 if index != 'nonce' : # Otherwise, only 'nonce': <payload> acceptable
106108 index ,payload = None ,record # ...if not; then records are not indexed.
107109
110+ payload = payload .strip ()
111+ log .debug ( f"Detect record { index :>5} : { payload !r} " )
112+ if not payload :
113+ continue
114+
115+ # Non-empty payload; process as either encrypted or raw JSON.
108116 try :
109117 if cipher :
110118 if nonce is None or index == 'nonce' :
@@ -113,7 +121,7 @@ def accountgroups_input(
113121 try :
114122 assert index == 'nonce' , \
115123 f"Failed to find 'nonce' enumeration prefix on first record: { record !r} "
116- ciphertext = bytearray ( codecs .decode ( payload . strip () , 'hex_codec' ))
124+ ciphertext = bytearray ( codecs .decode ( payload , 'hex_codec' ))
117125 nonce = bytes ( cipher .decrypt ( b'\x00 ' * 12 , ciphertext ))
118126 except Exception as exc :
119127 message = f"Failed to recover nonce from { record !r} ; cannot proceed: { exc } "
@@ -122,6 +130,7 @@ def accountgroups_input(
122130 log .info ( f"Decrypting accountgroups with nonce: { nonce .hex ()} " )
123131 continue
124132
133+ log .debug ( f"Decrypt index { index :>5} : { payload !r} " )
125134 nonce_now = nonce_add ( nonce , index )
126135 ciphertext = bytearray ( bytes .fromhex ( payload ))
127136 plaintext = bytes ( cipher .decrypt ( nonce_now , ciphertext ))
@@ -131,6 +140,7 @@ def accountgroups_input(
131140 log .warning ( f"Discarding invalid record { record !r} : { exc !r} " )
132141 yield None , None
133142 else :
143+ log .debug ( f"Decoded index { index :>5} : { group !r} " )
134144 yield int (index ), group
135145
136146
0 commit comments