How to decode cbor encoded hex string using perl libraries?

120 views Asked by At

I have a cbor encoded hex string.

when decoding using CBOR::XS

But I am getting an error as garbage after CBOR object, at offset 2 (octet 0x41) at new.pl line 6.

use CBOR::XS;
# Replace this with your CBOR-encoded hex data
my $hex_data = "";

# Decode CBOR data
my $decoded_data = CBOR::XS::decode_cbor($hex_data);
# Manually format the decoded data
use Data::Dumper;

print Dumper($decoded_data);
1

There are 1 answers

1
ikegami On BEST ANSWER

The sub does not want the hex representation of the bytes but the bytes themselves.

my $data = pack "H*", $hex_data;