tools.berdecode: catch exception during decoding

This commit is contained in:
p1-bmu 2022-03-07 11:51:02 +01:00
parent 736458858e
commit b9a5012b95
1 changed files with 9 additions and 4 deletions

View File

@ -92,10 +92,15 @@ def main():
char = Charpy(buf)
cnt = 0
while char.len_bit() >= 16:
Obj, V = ASN1CodecBER.decode_tlv_ws(char)
print('\n' + 14*'--' + ' object %i ' % cnt + 14*'--' + '\n')
pprint.pprint(V)
cnt += 1
try:
Obj, V = ASN1CodecBER.decode_tlv_ws(char)
except Exception as err:
print('Invalid BER buffer: %s' % err)
char._cur += 16
else:
print('\n' + 14*'--' + ' object %i ' % cnt + 14*'--' + '\n')
pprint.pprint(V)
cnt += 1
return 0
if __name__ == '__main__':