0

I I have a base64 string which I want to decode to its TLV origin then parse the TLV and pring data as regular strings:

import tlv8 ,base64

base64QR ="ASZNYWdpYyBGbG9vcmluZyBHZW5lcmFsIENvbnRyYWN0aW5nIEVzdAIPMzAwNjk2MjA4MTAwMDAzAxQyMDIzLTAyLTIwVDExOjI3OjU2WgQGNDAwLjY4BQU1Mi4yNg=="
rawByte = base64.b64decode(base64QR)

structure1 = {
1: tlv8.DataType.STRING,
2: tlv8.DataType.STRING,
3: tlv8.DataType.STRING,
4: tlv8.DataType.STRING,
5: tlv8.DataType.STRING
}

print( list(tlv8.decode(rawByte, structure1)))

However , when I print the result , I get memory address instead of real values - below is the output:

[<tlv8.Entry object at 0x00000243034EEFD0>, <tlv8.Entry object at 0x00000243034EF010>, <tlv8.Entry object at 0x00000243035A7210>, <tlv8.Entry object at 0x00000243035A72D0>, <tlv8.Entry object at 0x00000243035A7390>]

how can I get the values instead of memory address?

I have used base64 and TLV8 module Thanks

  • What does the documentation of the `tlv8` module say about the attributes and methods of an `Entry` object. – mkrieger1 Mar 03 '23 at 11:51
  • A TLV8 entry consists of the following parts: the type: this 8 bit field denotes the type of information that is represented by the data. the length: this 8 bit field denotes the length of the data (this does not include the 2 bytes for type and length. For data longer than 255 bytes, there is a defined procedure available. the value: these length bytes represent the value of this TLV. – Null Zero Mar 03 '23 at 12:06
  • More details can be found here : https://pypi.org/project/tlv8/ – Null Zero Mar 03 '23 at 12:07
  • So you should probably use the value attribute that was mentioned. Or follow the examples under "Decode a bytes representation" in the page you have linked. e.g. apparently there is a `format_string` function which can display `Entry` objects in human-readable form. – mkrieger1 Mar 03 '23 at 12:56
  • It worked by making these changes : final_output= tlv8.decode(rawByte, structure1) print(tlv8.format_string(final_output)) SOLVED - THANKS – Null Zero Mar 03 '23 at 15:11

0 Answers0